@@ -20,36 +20,35 @@ | |||
package org.sonar.server.exceptions; | |||
import com.google.common.base.Objects; | |||
import java.util.List; | |||
import org.sonar.api.utils.ValidationMessages; | |||
import java.util.List; | |||
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST; | |||
/** | |||
* Request is not valid and can not be processed. | |||
*/ | |||
public class BadRequestException extends ServerException { | |||
private static final int BAD_REQUEST = 400; | |||
private final Errors errors; | |||
public BadRequestException(String l10nKey, Object... l10nParams) { | |||
super(BAD_REQUEST); | |||
super(HTTP_BAD_REQUEST); | |||
this.errors = new Errors().add(Message.of(l10nKey, l10nParams)); | |||
} | |||
public BadRequestException(List<Message> messages) { | |||
super(BAD_REQUEST); | |||
super(HTTP_BAD_REQUEST); | |||
this.errors = new Errors().add(messages); | |||
} | |||
public BadRequestException(Errors e) { | |||
super(BAD_REQUEST); | |||
super(HTTP_BAD_REQUEST); | |||
this.errors = e; | |||
} | |||
public BadRequestException(ValidationMessages validationMessages) { | |||
super(BAD_REQUEST); | |||
super(HTTP_BAD_REQUEST); | |||
this.errors = new Errors(); | |||
for (String s : validationMessages.getErrors()) { | |||
errors.add(Message.of(s)); |
@@ -21,14 +21,14 @@ package org.sonar.server.exceptions; | |||
import com.google.common.base.Preconditions; | |||
import static java.net.HttpURLConnection.HTTP_FORBIDDEN; | |||
/** | |||
* Permission denied. User does not have the required permissions. | |||
*/ | |||
public class ForbiddenException extends ServerException { | |||
private static final int FORBIDDEN = 403; | |||
public ForbiddenException(String message) { | |||
super(FORBIDDEN, Preconditions.checkNotNull(message)); | |||
super(HTTP_FORBIDDEN, Preconditions.checkNotNull(message)); | |||
} | |||
} |
@@ -19,15 +19,15 @@ | |||
*/ | |||
package org.sonar.server.exceptions; | |||
public class NotFoundException extends ServerException { | |||
import static java.net.HttpURLConnection.HTTP_NOT_FOUND; | |||
private static final int NOT_FOUND = 404; | |||
public class NotFoundException extends ServerException { | |||
public NotFoundException() { | |||
super(NOT_FOUND); | |||
super(HTTP_NOT_FOUND); | |||
} | |||
public NotFoundException(String message) { | |||
super(NOT_FOUND, message); | |||
super(HTTP_NOT_FOUND, message); | |||
} | |||
} |
@@ -19,18 +19,18 @@ | |||
*/ | |||
package org.sonar.server.exceptions; | |||
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; | |||
/** | |||
* User needs to be authenticated. HTTP request is generally redirected to login form. | |||
*/ | |||
public class UnauthorizedException extends ServerException { | |||
private static final int UNAUTHORIZED = 401; | |||
public UnauthorizedException() { | |||
super(UNAUTHORIZED); | |||
super(HTTP_UNAUTHORIZED); | |||
} | |||
public UnauthorizedException(String message) { | |||
super(UNAUTHORIZED, message); | |||
super(HTTP_UNAUTHORIZED, message); | |||
} | |||
} |
@@ -39,8 +39,10 @@ public interface Rule { | |||
String name(); | |||
@CheckForNull | |||
String htmlDescription(); | |||
@CheckForNull | |||
String markdownDescription(); | |||
String effortToFixDescription(); |
@@ -88,11 +88,13 @@ public class RuleDoc extends BaseDoc implements Rule { | |||
} | |||
@Override | |||
@CheckForNull | |||
public String htmlDescription() { | |||
return getNullableField(RuleNormalizer.RuleField.HTML_DESCRIPTION.field()); | |||
} | |||
@Override | |||
@CheckForNull | |||
public String markdownDescription() { | |||
return getNullableField(RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION.field()); | |||
} |
@@ -20,26 +20,27 @@ | |||
package org.sonar.server.rule.ws; | |||
import com.google.common.collect.Maps; | |||
import com.google.common.collect.Sets; | |||
import org.sonar.api.server.ServerSide; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
import java.util.Map; | |||
import javax.annotation.CheckForNull; | |||
import org.sonar.api.resources.Language; | |||
import org.sonar.api.resources.Languages; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.api.utils.text.JsonWriter; | |||
import org.sonar.db.qualityprofile.ActiveRuleKey; | |||
import org.sonar.db.qualityprofile.QualityProfileDto; | |||
import org.sonar.server.qualityprofile.ActiveRule; | |||
import org.sonar.server.qualityprofile.QProfileLoader; | |||
import org.sonar.server.rule.Rule; | |||
import org.sonar.server.rule.index.RuleQuery; | |||
import org.sonarqube.ws.Rules; | |||
import org.sonarqube.ws.Rules.SearchResponse; | |||
import org.sonarqube.ws.Rules.ShowResponse; | |||
import javax.annotation.CheckForNull; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
import java.util.Map; | |||
import static com.google.common.collect.Sets.newHashSet; | |||
/** | |||
* Add details about active rules to api/rules/search and api/rules/show | |||
@@ -58,80 +59,74 @@ public class ActiveRuleCompleter { | |||
this.languages = languages; | |||
} | |||
void completeSearch(RuleQuery query, Collection<Rule> rules, JsonWriter json) { | |||
Collection<String> harvestedProfileKeys = writeActiveRules(json, query, rules); | |||
writeProfiles(json, harvestedProfileKeys); | |||
void completeSearch(RuleQuery query, Collection<Rule> rules, SearchResponse.Builder searchResponse) { | |||
Collection<String> harvestedProfileKeys = writeActiveRules(searchResponse, query, rules); | |||
searchResponse.setQProfiles(buildQProfiles(harvestedProfileKeys)); | |||
} | |||
private Collection<String> writeActiveRules(JsonWriter json, RuleQuery query, Collection<Rule> rules) { | |||
Collection<String> qProfileKeys = Sets.newHashSet(); | |||
private Collection<String> writeActiveRules(SearchResponse.Builder response, RuleQuery query, Collection<Rule> rules) { | |||
Collection<String> qProfileKeys = newHashSet(); | |||
Rules.Actives.Builder activesBuilder = response.getActivesBuilder(); | |||
json.name("actives").beginObject(); | |||
String profileKey = query.getQProfileKey(); | |||
if (profileKey != null) { | |||
// Load details of active rules on the selected profile | |||
for (Rule rule : rules) { | |||
ActiveRule activeRule = loader.getActiveRule(ActiveRuleKey.of(profileKey, rule.key())); | |||
if (activeRule != null) { | |||
qProfileKeys = writeActiveRules(rule.key(), Arrays.asList(activeRule), json); | |||
qProfileKeys = writeActiveRules(rule.key(), Arrays.asList(activeRule), activesBuilder); | |||
} | |||
} | |||
} else { | |||
// Load details of all active rules | |||
for (Rule rule : rules) { | |||
qProfileKeys = writeActiveRules(rule.key(), loader.findActiveRulesByRule(rule.key()), json); | |||
qProfileKeys = writeActiveRules(rule.key(), loader.findActiveRulesByRule(rule.key()), activesBuilder); | |||
} | |||
} | |||
json.endObject(); | |||
response.setActives(activesBuilder); | |||
return qProfileKeys; | |||
} | |||
void completeShow(Rule rule, JsonWriter json) { | |||
json.name("actives").beginArray(); | |||
void completeShow(Rule rule, ShowResponse.Builder response) { | |||
for (ActiveRule activeRule : loader.findActiveRulesByRule(rule.key())) { | |||
writeActiveRule(activeRule, json); | |||
response.addActives(buildActiveRuleResponse(activeRule)); | |||
} | |||
json.endArray(); | |||
} | |||
private Collection<String> writeActiveRules(RuleKey ruleKey, Collection<ActiveRule> activeRules, JsonWriter json) { | |||
Collection<String> qProfileKeys = Sets.newHashSet(); | |||
if (!activeRules.isEmpty()) { | |||
json.name(ruleKey.toString()); | |||
json.beginArray(); | |||
for (ActiveRule activeRule : activeRules) { | |||
qProfileKeys.add(writeActiveRule(activeRule, json)); | |||
} | |||
json.endArray(); | |||
private Collection<String> writeActiveRules(RuleKey ruleKey, Collection<ActiveRule> activeRules, Rules.Actives.Builder activesBuilder) { | |||
Collection<String> qProfileKeys = newHashSet(); | |||
Rules.ActiveList.Builder activeRulesListResponse = Rules.ActiveList.newBuilder(); | |||
for (ActiveRule activeRule : activeRules) { | |||
activeRulesListResponse.addActiveList(buildActiveRuleResponse(activeRule)); | |||
qProfileKeys.add(activeRule.key().qProfile()); | |||
} | |||
activesBuilder | |||
.getMutableActives() | |||
.put(ruleKey.toString(), activeRulesListResponse.build()); | |||
return qProfileKeys; | |||
} | |||
private String writeActiveRule(ActiveRule activeRule, JsonWriter json) { | |||
json | |||
.beginObject() | |||
.prop("qProfile", activeRule.key().qProfile()) | |||
.prop("inherit", activeRule.inheritance().toString()) | |||
.prop("severity", activeRule.severity()); | |||
private Rules.Active buildActiveRuleResponse(ActiveRule activeRule) { | |||
Rules.Active.Builder activeRuleResponse = Rules.Active.newBuilder(); | |||
activeRuleResponse.setQProfile(activeRule.key().qProfile()); | |||
activeRuleResponse.setInherit(activeRule.inheritance().toString()); | |||
activeRuleResponse.setSeverity(activeRule.severity()); | |||
ActiveRuleKey parentKey = activeRule.parentKey(); | |||
if (parentKey != null) { | |||
json.prop("parent", parentKey.toString()); | |||
activeRuleResponse.setParent(parentKey.toString()); | |||
} | |||
json.name("params").beginArray(); | |||
Rules.Active.Param.Builder paramBuilder = Rules.Active.Param.newBuilder(); | |||
for (Map.Entry<String, String> param : activeRule.params().entrySet()) { | |||
json | |||
.beginObject() | |||
.prop("key", param.getKey()) | |||
.prop("value", param.getValue()) | |||
.endObject(); | |||
activeRuleResponse.addParams(paramBuilder.clear() | |||
.setKey(param.getKey()) | |||
.setValue(param.getValue())); | |||
} | |||
json.endArray().endObject(); | |||
return activeRule.key().qProfile(); | |||
return activeRuleResponse.build(); | |||
} | |||
private void writeProfiles(JsonWriter json, Collection<String> harvestedProfileKeys) { | |||
private Rules.QProfiles.Builder buildQProfiles(Collection<String> harvestedProfileKeys) { | |||
Map<String, QualityProfileDto> qProfilesByKey = Maps.newHashMap(); | |||
for (String qProfileKey : harvestedProfileKeys) { | |||
if (!qProfilesByKey.containsKey(qProfileKey)) { | |||
@@ -147,11 +142,14 @@ public class ActiveRuleCompleter { | |||
} | |||
} | |||
} | |||
json.name("qProfiles").beginObject(); | |||
Rules.QProfiles.Builder qProfilesResponse = Rules.QProfiles.newBuilder(); | |||
Map<String, Rules.QProfile> qProfilesMapResponse = qProfilesResponse.getMutableQProfiles(); | |||
for (QualityProfileDto profile : qProfilesByKey.values()) { | |||
writeProfile(json, profile); | |||
writeProfile(qProfilesMapResponse, profile); | |||
} | |||
json.endObject(); | |||
return qProfilesResponse; | |||
} | |||
@CheckForNull | |||
@@ -159,15 +157,22 @@ public class ActiveRuleCompleter { | |||
return loader.getByKey(qProfileKey); | |||
} | |||
private void writeProfile(JsonWriter json, QualityProfileDto profile) { | |||
Language language = languages.get(profile.getLanguage()); | |||
String langName = language == null ? profile.getLanguage() : language.getName(); | |||
json.name(profile.getKey()).beginObject() | |||
.prop("name", profile.getName()) | |||
.prop("lang", profile.getLanguage()) | |||
.prop("langName", langName) | |||
.prop("parent", profile.getParentKee()) | |||
.endObject(); | |||
private void writeProfile(Map<String, Rules.QProfile> profilesResponse, QualityProfileDto profile) { | |||
Rules.QProfile.Builder profileResponse = Rules.QProfile.newBuilder(); | |||
if (profile.getName() != null) { | |||
profileResponse.setName(profile.getName()); | |||
} | |||
if (profile.getLanguage() != null) { | |||
profileResponse.setLang(profile.getLanguage()); | |||
Language language = languages.get(profile.getLanguage()); | |||
String langName = language == null ? profile.getLanguage() : language.getName(); | |||
profileResponse.setLangName(langName); | |||
} | |||
if (profile.getParentKee() != null) { | |||
profileResponse.setParent(profile.getParentKee()); | |||
} | |||
profilesResponse.put(profile.getKey(), profileResponse.build()); | |||
} | |||
} |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.server.rule.ws; | |||
import com.google.common.base.Strings; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rule.RuleStatus; | |||
import org.sonar.api.rule.Severity; | |||
@@ -27,16 +26,16 @@ import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.api.utils.KeyValueFormat; | |||
import org.sonar.api.utils.text.JsonWriter; | |||
import org.sonar.server.exceptions.BadRequestException; | |||
import org.sonar.server.plugins.MimeTypes; | |||
import org.sonar.server.rule.NewRule; | |||
import org.sonar.server.rule.ReactivationException; | |||
import org.sonar.server.rule.Rule; | |||
import org.sonar.server.rule.RuleService; | |||
import org.sonarqube.ws.Rules; | |||
import java.io.OutputStreamWriter; | |||
import java.nio.charset.StandardCharsets; | |||
import static com.google.common.base.Strings.isNullOrEmpty; | |||
import static java.net.HttpURLConnection.HTTP_CONFLICT; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
/** | |||
* @since 4.4 | |||
@@ -120,15 +119,15 @@ public class CreateAction implements RulesWsAction { | |||
} | |||
@Override | |||
public void handle(Request request, Response response) { | |||
public void handle(Request request, Response response) throws Exception { | |||
String customKey = request.param(PARAM_CUSTOM_KEY); | |||
String manualKey = request.param(PARAM_MANUAL_KEY); | |||
if (Strings.isNullOrEmpty(customKey) && Strings.isNullOrEmpty(manualKey)) { | |||
if (isNullOrEmpty(customKey) && isNullOrEmpty(manualKey)) { | |||
throw new BadRequestException(String.format("Either '%s' or '%s' parameters should be set", PARAM_CUSTOM_KEY, PARAM_MANUAL_KEY)); | |||
} | |||
try { | |||
if (!Strings.isNullOrEmpty(customKey)) { | |||
if (!isNullOrEmpty(customKey)) { | |||
NewRule newRule = NewRule.createForCustomRule(customKey, RuleKey.parse(request.mandatoryParam(PARAM_TEMPLATE_KEY))) | |||
.setName(request.mandatoryParam(PARAM_NAME)) | |||
.setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION)) | |||
@@ -136,40 +135,42 @@ public class CreateAction implements RulesWsAction { | |||
.setStatus(RuleStatus.valueOf(request.mandatoryParam(PARAM_STATUS))) | |||
.setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION)); | |||
String params = request.param(PARAMS); | |||
if (!Strings.isNullOrEmpty(params)) { | |||
if (!isNullOrEmpty(params)) { | |||
newRule.setParameters(KeyValueFormat.parse(params)); | |||
} | |||
writeResponse(response, service.create(newRule)); | |||
writeResponse(request, response, service.create(newRule)); | |||
} | |||
if (!Strings.isNullOrEmpty(manualKey)) { | |||
if (!isNullOrEmpty(manualKey)) { | |||
NewRule newRule = NewRule.createForManualRule(manualKey) | |||
.setName(request.mandatoryParam(PARAM_NAME)) | |||
.setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION)) | |||
.setSeverity(request.param(PARAM_SEVERITY)) | |||
.setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION)); | |||
writeResponse(response, service.create(newRule)); | |||
writeResponse(request, response, service.create(newRule)); | |||
} | |||
} catch (ReactivationException e) { | |||
write409(response, e.ruleKey()); | |||
write409(request, response, e.ruleKey()); | |||
} | |||
} | |||
private void writeResponse(Response response, RuleKey ruleKey) { | |||
private void writeResponse(Request request, Response response, RuleKey ruleKey) throws Exception { | |||
Rule rule = service.getNonNullByKey(ruleKey); | |||
JsonWriter json = response.newJsonWriter().beginObject().name("rule"); | |||
mapping.write(rule, json, null /* TODO replace by SearchOptions immutable constant */); | |||
json.endObject().close(); | |||
Rules.CreateResponse createResponse = Rules.CreateResponse.newBuilder() | |||
.setRule(mapping.buildRuleResponse(rule, null /* TODO replace by SearchOptions immutable constant */)) | |||
.build(); | |||
writeProtobuf(createResponse, request, response); | |||
} | |||
private void write409(Response response, RuleKey ruleKey) { | |||
private void write409(Request request, Response response, RuleKey ruleKey) throws Exception { | |||
Rule rule = service.getNonNullByKey(ruleKey); | |||
Response.Stream stream = response.stream(); | |||
stream.setStatus(409); | |||
stream.setMediaType(MimeTypes.JSON); | |||
JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8)).beginObject().name("rule"); | |||
mapping.write(rule, json, null /* TODO replace by SearchOptions immutable constant */); | |||
json.endObject().close(); | |||
response.stream().setStatus(HTTP_CONFLICT); | |||
Rules.CreateResponse createResponse = Rules.CreateResponse.newBuilder() | |||
.setRule(mapping.buildRuleResponse(rule, null /* TODO replace by SearchOptions immutable constant */)) | |||
.build(); | |||
writeProtobuf(createResponse, request, response); | |||
} | |||
} |
@@ -19,27 +19,35 @@ | |||
*/ | |||
package org.sonar.server.rule.ws; | |||
import com.google.common.base.Function; | |||
import com.google.common.collect.Maps; | |||
import java.util.Collections; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nonnull; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.resources.Language; | |||
import org.sonar.api.resources.Languages; | |||
import org.sonar.api.server.debt.DebtCharacteristic; | |||
import org.sonar.api.server.debt.DebtModel; | |||
import org.sonar.api.server.debt.DebtRemediationFunction; | |||
import org.sonar.api.utils.text.JsonWriter; | |||
import org.sonar.markdown.Markdown; | |||
import org.sonar.server.rule.Rule; | |||
import org.sonar.server.rule.RuleParam; | |||
import org.sonar.server.rule.index.RuleDoc; | |||
import org.sonar.server.rule.index.RuleNormalizer; | |||
import org.sonar.server.search.IndexField; | |||
import org.sonar.server.search.QueryContext; | |||
import org.sonar.server.search.ws.BaseMapping; | |||
import org.sonar.server.text.MacroInterpreter; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import java.util.Collection; | |||
import java.util.Map; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonarqube.ws.Common; | |||
import org.sonarqube.ws.Rules; | |||
import static com.google.common.collect.FluentIterable.from; | |||
import static org.sonar.api.utils.DateUtils.formatDateTime; | |||
/** | |||
* Conversion of {@link org.sonar.server.rule.index.RuleDoc} to WS JSON document | |||
@@ -47,18 +55,22 @@ import org.sonar.server.user.UserSession; | |||
public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> { | |||
private final DebtModel debtModel; | |||
private final Languages languages; | |||
private final MacroInterpreter macroInterpreter; | |||
public RuleMapping(final Languages languages, final MacroInterpreter macroInterpreter, final DebtModel debtModel, UserSession userSession) { | |||
super(userSession); | |||
this.debtModel = debtModel; | |||
this.languages = languages; | |||
this.macroInterpreter = macroInterpreter; | |||
mapBasicFields(languages); | |||
mapDescriptionFields(macroInterpreter); | |||
mapBasicFields(); | |||
mapDescriptionFields(); | |||
mapDebtFields(); | |||
mapParamFields(); | |||
} | |||
private void mapBasicFields(final Languages languages) { | |||
private void mapBasicFields() { | |||
map("repo", RuleNormalizer.RuleField.REPOSITORY.field()); | |||
map("name", RuleNormalizer.RuleField.NAME.field()); | |||
mapDateTime("createdAt", RuleNormalizer.RuleField.CREATED_AT.field()); | |||
@@ -70,195 +82,357 @@ public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> { | |||
mapArray("tags", RuleNormalizer.RuleField.TAGS.field()); | |||
mapArray("sysTags", RuleNormalizer.RuleField.SYSTEM_TAGS.field()); | |||
map("lang", RuleNormalizer.RuleField.LANGUAGE.field()); | |||
map("langName", new IndexMapper<RuleDoc, RuleMappingContext>(RuleNormalizer.RuleField.LANGUAGE.field()) { | |||
@Override | |||
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { | |||
Language lang = languages.get(rule.language()); | |||
json.prop("langName", lang != null ? lang.getName() : null); | |||
} | |||
}); | |||
map("langName", RuleNormalizer.RuleField.LANGUAGE.field()); | |||
} | |||
private void mapDescriptionFields(final MacroInterpreter macroInterpreter) { | |||
map("htmlDesc", new IndexMapper<RuleDoc, RuleMappingContext>(RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION.field(), RuleNormalizer.RuleField.HTML_DESCRIPTION.field()) { | |||
@Override | |||
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { | |||
if (rule.markdownDescription() != null) { | |||
json.prop("htmlDesc", macroInterpreter.interpret(Markdown.convertToHtml(rule.markdownDescription()))); | |||
} else { | |||
json.prop("htmlDesc", macroInterpreter.interpret(rule.htmlDescription())); | |||
} | |||
} | |||
}); | |||
private void mapDescriptionFields() { | |||
map("htmlDesc", RuleNormalizer.RuleField.HTML_DESCRIPTION.field()); | |||
map("mdDesc", RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION.field()); | |||
map("noteLogin", RuleNormalizer.RuleField.NOTE_LOGIN.field()); | |||
map("mdNote", RuleNormalizer.RuleField.NOTE.field()); | |||
map("htmlNote", new IndexMapper<RuleDoc, RuleMappingContext>(RuleNormalizer.RuleField.NOTE.field()) { | |||
@Override | |||
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { | |||
String markdownNote = rule.markdownNote(); | |||
if (markdownNote != null) { | |||
json.prop("htmlNote", macroInterpreter.interpret(Markdown.convertToHtml(markdownNote))); | |||
} | |||
} | |||
}); | |||
map("htmlNote", RuleNormalizer.RuleField.NOTE.field()); | |||
} | |||
private void mapDebtFields() { | |||
map("defaultDebtChar", new IndexStringMapper("defaultDebtChar", RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field())); | |||
map("defaultDebtSubChar", new IndexStringMapper("defaultDebtSubChar", RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field())); | |||
map("debtChar", RuleNormalizer.RuleField.CHARACTERISTIC.field()); | |||
map("debtSubChar", RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()); | |||
map("debtChar", new CharacteristicMapper()); | |||
map("debtSubChar", new SubCharacteristicMapper()); | |||
map("debtCharName", new CharacteristicNameMapper()); | |||
map("debtSubCharName", new SubCharacteristicNameMapper()); | |||
map("debtCharName", RuleNormalizer.RuleField.CHARACTERISTIC.field()); | |||
map("debtSubCharName", RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()); | |||
map("defaultDebtRemFn", new IndexStringMapper("defaultDebtRemFnType", RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_TYPE.field())); | |||
map("defaultDebtRemFn", new IndexStringMapper("defaultDebtRemFnCoeff", RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_COEFFICIENT.field())); | |||
map("defaultDebtRemFn", new IndexStringMapper("defaultDebtRemFnOffset", RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_OFFSET.field())); | |||
map("effortToFixDescription", RuleNormalizer.RuleField.FIX_DESCRIPTION.field()); | |||
map("debtOverloaded", new OverriddenMapper()); | |||
map("debtOverloaded", new SimpleMapper( | |||
RuleNormalizer.RuleField.CHARACTERISTIC_OVERLOADED.field(), | |||
RuleNormalizer.RuleField.SUB_CHARACTERISTIC_OVERLOADED.field(), | |||
RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE_OVERLOADED.field())); | |||
map("debtRemFn", new IndexStringMapper("debtRemFnType", RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE.field())); | |||
map("debtRemFn", new IndexStringMapper("debtRemFnCoeff", RuleNormalizer.RuleField.DEBT_FUNCTION_COEFFICIENT.field())); | |||
map("debtRemFn", new IndexStringMapper("debtRemFnOffset", RuleNormalizer.RuleField.DEBT_FUNCTION_OFFSET.field())); | |||
} | |||
public static class EffectiveDebtRemFn extends IndexStringMapper<RuleDoc,RuleMappingContext> { | |||
private void mapParamFields() { | |||
map("params", RuleNormalizer.RuleField.PARAMS.field()); | |||
} | |||
public Rules.Rule buildRuleResponse(Rule ruleDoc, @Nullable QueryContext queryContext) { | |||
Rules.Rule.Builder ruleResponse = Rules.Rule.newBuilder(); | |||
RuleMappingContext context = new RuleMappingContext(); | |||
Set<String> fieldsToReturn = fieldsToReturn(queryContext); | |||
ruleResponse.setKey(ruleDoc.key().toString()); | |||
setRepository(ruleResponse, ruleDoc, fieldsToReturn); | |||
setDebtCharacteristicNames(ruleResponse, ruleDoc, queryContext, context); | |||
setDebtSubCharacteristicNames(ruleResponse, ruleDoc, queryContext, context); | |||
setName(ruleResponse, ruleDoc, fieldsToReturn); | |||
setStatus(ruleResponse, ruleDoc, fieldsToReturn); | |||
setTags(ruleResponse, ruleDoc, fieldsToReturn); | |||
setSysTags(ruleResponse, ruleDoc, fieldsToReturn); | |||
setParams(ruleResponse, ruleDoc, fieldsToReturn); | |||
setCreatedAt(ruleResponse, ruleDoc, fieldsToReturn); | |||
setDescriptionFields(ruleResponse, ruleDoc, fieldsToReturn); | |||
setSeverity(ruleResponse, ruleDoc, fieldsToReturn); | |||
setInternalKey(ruleResponse, ruleDoc, fieldsToReturn); | |||
setLanguage(ruleResponse, ruleDoc, fieldsToReturn); | |||
setIsTemplate(ruleResponse, ruleDoc, fieldsToReturn); | |||
setTemplateKey(ruleResponse, ruleDoc, fieldsToReturn); | |||
setDebtRemediationFunctionFields(ruleResponse, ruleDoc, fieldsToReturn); | |||
setDefaultDebtRemediationFunctionFields(ruleResponse, ruleDoc, fieldsToReturn); | |||
setIsDebtOverloaded(ruleResponse, ruleDoc, fieldsToReturn); | |||
setDefaultDebtChar(ruleResponse, ruleDoc, fieldsToReturn); | |||
setDefaultDebtSubChar(ruleResponse, ruleDoc, fieldsToReturn); | |||
setEffortToFixDescription(ruleResponse, ruleDoc, fieldsToReturn); | |||
return ruleResponse.build(); | |||
} | |||
public EffectiveDebtRemFn(String key, String indexKey, String defaultIndexKey) { | |||
super(key, indexKey, defaultIndexKey); | |||
private static void setRepository(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.REPOSITORY)) { | |||
ruleResponse.setRepo(ruleDoc.key().repository()); | |||
} | |||
} | |||
@Override | |||
public void write(JsonWriter json, RuleDoc doc, RuleMappingContext context) { | |||
if(doc.debtOverloaded()){ | |||
Object val = doc.getNullableField(indexFields[0]); | |||
json.prop(key, val != null ? val.toString() : null); | |||
} else { | |||
super.write(json,doc,context); | |||
private static void setEffortToFixDescription(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.FIX_DESCRIPTION) && ruleDoc.effortToFixDescription() != null) { | |||
ruleResponse.setEffortToFixDescription(ruleDoc.effortToFixDescription()); | |||
} | |||
} | |||
private static void setDefaultDebtSubChar(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, "defaultDebtSubChar") && ruleDoc.defaultDebtSubCharacteristicKey() != null) { | |||
ruleResponse.setDefaultDebtSubChar(ruleDoc.defaultDebtSubCharacteristicKey()); | |||
} | |||
} | |||
private static void setDefaultDebtChar(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, "defaultDebtChar") && ruleDoc.defaultDebtCharacteristicKey() != null) { | |||
ruleResponse.setDefaultDebtChar(ruleDoc.defaultDebtCharacteristicKey()); | |||
} | |||
} | |||
private static void setIsDebtOverloaded(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, "debtOverloaded")) { | |||
ruleResponse.setDebtOverloaded(ruleToOverloaded(ruleDoc)); | |||
} | |||
} | |||
private static void setDefaultDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, "defaultDebtRemFn")) { | |||
DebtRemediationFunction defaultDebtRemediationFunction = ruleDoc.defaultDebtRemediationFunction(); | |||
if (defaultDebtRemediationFunction != null) { | |||
if (defaultDebtRemediationFunction.coefficient() != null) { | |||
ruleResponse.setDefaultDebtRemFnCoeff(defaultDebtRemediationFunction.coefficient()); | |||
} | |||
if (defaultDebtRemediationFunction.offset() != null) { | |||
ruleResponse.setDefaultDebtRemFnOffset(defaultDebtRemediationFunction.offset()); | |||
} | |||
if (defaultDebtRemediationFunction.type() != null) { | |||
ruleResponse.setDefaultDebtRemFnType(defaultDebtRemediationFunction.type().name()); | |||
} | |||
} | |||
} | |||
} | |||
private void mapParamFields() { | |||
map("params", new IndexMapper<RuleDoc, RuleMappingContext>(RuleNormalizer.RuleField.PARAMS.field()) { | |||
@Override | |||
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { | |||
json.name("params").beginArray(); | |||
for (RuleParam param : rule.params()) { | |||
json | |||
.beginObject() | |||
.prop("key", param.key()) | |||
.prop("htmlDesc", param.description() == null ? null : Markdown.convertToHtml(param.description())) | |||
.prop("type", param.type().type()) | |||
.prop("defaultValue", param.defaultValue()) | |||
.endObject(); | |||
private static void setDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, "debtRemFn")) { | |||
DebtRemediationFunction debtRemediationFunction = ruleDoc.debtRemediationFunction(); | |||
if (debtRemediationFunction != null) { | |||
if (debtRemediationFunction.type() != null) { | |||
ruleResponse.setDebtRemFnType(debtRemediationFunction.type().name()); | |||
} | |||
if (debtRemediationFunction.coefficient() != null) { | |||
ruleResponse.setDebtRemFnCoeff(debtRemediationFunction.coefficient()); | |||
} | |||
if (debtRemediationFunction.offset() != null) { | |||
ruleResponse.setDebtRemFnOffset(debtRemediationFunction.offset()); | |||
} | |||
json.endArray(); | |||
} | |||
}); | |||
} | |||
} | |||
public void write(Rule rule, JsonWriter json, @Nullable QueryContext queryContext) { | |||
RuleMappingContext context = new RuleMappingContext(); | |||
private void setDebtCharacteristicNames(Rules.Rule.Builder ruleResponse, Rule ruleDoc, @Nullable QueryContext queryContext, RuleMappingContext context) { | |||
if (needDebtCharacteristicNames(queryContext)) { | |||
String debtCharacteristicKey = rule.debtCharacteristicKey(); | |||
String debtCharacteristicKey = ruleDoc.debtCharacteristicKey(); | |||
if (debtCharacteristicKey != null) { | |||
// load debt characteristics if requested | |||
context.add(debtModel.characteristicByKey(debtCharacteristicKey)); | |||
buildCharacteristicRuleResponse(ruleResponse, ruleDoc, context); | |||
} | |||
} | |||
} | |||
private void setDebtSubCharacteristicNames(Rules.Rule.Builder ruleResponse, Rule ruleDoc, @Nullable QueryContext queryContext, RuleMappingContext context) { | |||
if (needDebtSubCharacteristicNames(queryContext)) { | |||
String debtSubCharacteristicKey = rule.debtSubCharacteristicKey(); | |||
String debtSubCharacteristicKey = ruleDoc.debtSubCharacteristicKey(); | |||
if (debtSubCharacteristicKey != null) { | |||
context.add(debtModel.characteristicByKey(debtSubCharacteristicKey)); | |||
buildDebtSubCharacteristicRuleResponse(ruleResponse, ruleDoc, context); | |||
} | |||
} | |||
doWrite((RuleDoc) rule, context, json, queryContext); | |||
} | |||
public void write(Collection<Rule> rules, JsonWriter json, @Nullable QueryContext queryContext) { | |||
if (!rules.isEmpty()) { | |||
RuleMappingContext context = new RuleMappingContext(); | |||
if (needDebtCharacteristicNames(queryContext) || needDebtSubCharacteristicNames(queryContext)) { | |||
// load all debt characteristics | |||
context.addAll(debtModel.allCharacteristics()); | |||
} | |||
for (Rule rule : rules) { | |||
doWrite((RuleDoc) rule, context, json, queryContext); | |||
} | |||
private static Set<String> fieldsToReturn(@Nullable QueryContext queryContext) { | |||
return queryContext == null ? Collections.<String>emptySet() : queryContext.getFieldsToReturn(); | |||
} | |||
private static void setName(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.NAME) && ruleDoc.name() != null) { | |||
ruleResponse.setName(ruleDoc.name()); | |||
} | |||
} | |||
private boolean needDebtCharacteristicNames(@Nullable QueryContext context) { | |||
return context == null || context.getFieldsToReturn().contains("debtCharName"); | |||
private static void setStatus(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.STATUS) && ruleDoc.status() != null) { | |||
ruleResponse.setStatus(Common.RuleStatus.valueOf(ruleDoc.status().toString())); | |||
} | |||
} | |||
private boolean needDebtSubCharacteristicNames(@Nullable QueryContext context) { | |||
return context == null || context.getFieldsToReturn().contains("debtSubCharName"); | |||
private static void setTags(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.TAGS)) { | |||
ruleResponse.getTagsBuilder().addAllTags(ruleDoc.tags()); | |||
} | |||
} | |||
private static class CharacteristicMapper extends IndexMapper<RuleDoc, RuleMappingContext> { | |||
private CharacteristicMapper() { | |||
super(RuleNormalizer.RuleField.CHARACTERISTIC.field()); | |||
private static void setSysTags(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.SYSTEM_TAGS)) { | |||
ruleResponse.getSysTagsBuilder().addAllSysTags(ruleDoc.systemTags()); | |||
} | |||
} | |||
@Override | |||
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { | |||
String debtCharacteristicKey = rule.debtCharacteristicKey(); | |||
if (debtCharacteristicKey != null && !DebtCharacteristic.NONE.equals(debtCharacteristicKey)) { | |||
json.prop("debtChar", debtCharacteristicKey); | |||
private static void setParams(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.PARAMS)) { | |||
ruleResponse.getParamsBuilder().addAllParams(from(ruleDoc.params()) | |||
.transform(RuleParamToResponseRuleParam.INSTANCE) | |||
.toList()); | |||
} | |||
} | |||
private static void setCreatedAt(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.CREATED_AT) && ruleDoc.createdAt() != null) { | |||
ruleResponse.setCreatedAt(formatDateTime(ruleDoc.createdAt())); | |||
} | |||
} | |||
private void setDescriptionFields(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.HTML_DESCRIPTION)) { | |||
if (ruleDoc.markdownDescription() != null) { | |||
ruleResponse.setHtmlDesc(macroInterpreter.interpret(Markdown.convertToHtml(ruleDoc.markdownDescription()))); | |||
} else if (ruleDoc.htmlDescription() != null) { | |||
ruleResponse.setHtmlDesc(macroInterpreter.interpret(ruleDoc.htmlDescription())); | |||
} | |||
} | |||
if (shouldReturnField(fieldsToReturn, "htmlNote") && ruleDoc.markdownNote() != null) { | |||
ruleResponse.setHtmlNote(macroInterpreter.interpret(Markdown.convertToHtml(ruleDoc.markdownNote()))); | |||
} | |||
if (shouldReturnField(fieldsToReturn, "mdNote") && ruleDoc.markdownNote() != null) { | |||
ruleResponse.setMdNote(ruleDoc.markdownNote()); | |||
} | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION) && ruleDoc.markdownDescription() != null) { | |||
ruleResponse.setMdDesc(ruleDoc.markdownDescription()); | |||
} | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.NOTE_LOGIN) && ruleDoc.noteLogin() != null) { | |||
ruleResponse.setNoteLogin(ruleDoc.noteLogin()); | |||
} | |||
} | |||
private static class SubCharacteristicMapper extends IndexMapper<RuleDoc, RuleMappingContext> { | |||
private SubCharacteristicMapper() { | |||
super(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()); | |||
private static void setSeverity(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.SEVERITY) && ruleDoc.severity() != null) { | |||
ruleResponse.setSeverity(ruleDoc.severity()); | |||
} | |||
} | |||
@Override | |||
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { | |||
String debtSubCharacteristicKey = rule.debtSubCharacteristicKey(); | |||
if (debtSubCharacteristicKey != null && !DebtCharacteristic.NONE.equals(debtSubCharacteristicKey)) { | |||
json.prop("debtSubChar", debtSubCharacteristicKey); | |||
private static void setInternalKey(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.INTERNAL_KEY) && ruleDoc.internalKey() != null) { | |||
ruleResponse.setInternalKey(ruleDoc.internalKey()); | |||
} | |||
} | |||
private void setLanguage(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.LANGUAGE) && ruleDoc.language() != null) { | |||
ruleResponse.setLang(ruleDoc.language()); | |||
Language language = languages.get(ruleDoc.language()); | |||
if (language != null) { | |||
ruleResponse.setLangName(language.getName()); | |||
} | |||
} | |||
} | |||
private static class CharacteristicNameMapper extends IndexMapper<RuleDoc, RuleMappingContext> { | |||
private CharacteristicNameMapper() { | |||
super(RuleNormalizer.RuleField.CHARACTERISTIC.field()); | |||
private static void setIsTemplate(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.IS_TEMPLATE)) { | |||
ruleResponse.setIsTemplate(ruleDoc.isTemplate()); | |||
} | |||
} | |||
@Override | |||
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { | |||
json.prop("debtCharName", context.debtCharacteristicName(rule.debtCharacteristicKey())); | |||
private static void setTemplateKey(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) { | |||
if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.TEMPLATE_KEY) && ruleDoc.templateKey() != null) { | |||
ruleResponse.setTemplateKey(ruleDoc.templateKey().toString()); | |||
} | |||
} | |||
private static class SubCharacteristicNameMapper extends IndexMapper<RuleDoc, RuleMappingContext> { | |||
private SubCharacteristicNameMapper() { | |||
super(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()); | |||
private static boolean shouldReturnField(Set<String> fieldsToReturn, IndexField field) { | |||
return fieldsToReturn.isEmpty() || fieldsToReturn.contains(field.field()); | |||
} | |||
private static boolean shouldReturnField(Set<String> fieldsToReturn, String fieldName) { | |||
return fieldsToReturn.isEmpty() || fieldsToReturn.contains(fieldName); | |||
} | |||
private void buildCharacteristicRuleResponse(Rules.Rule.Builder ruleResponse, Rule ruleDoc, RuleMappingContext context) { | |||
String ruleCharacteristic = ruleToCharacteristic(ruleDoc); | |||
if (ruleCharacteristic != null) { | |||
ruleResponse.setDebtChar(ruleCharacteristic); | |||
String ruleCharacteristicName = ruleToCharacteristicName(ruleDoc, context); | |||
if (ruleCharacteristicName != null) { | |||
ruleResponse.setDebtCharName(ruleCharacteristicName); | |||
} | |||
} | |||
} | |||
@Override | |||
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { | |||
json.prop("debtSubCharName", context.debtCharacteristicName(rule.debtSubCharacteristicKey())); | |||
private void buildDebtSubCharacteristicRuleResponse(Rules.Rule.Builder ruleResponse, Rule ruleDoc, RuleMappingContext context) { | |||
String ruleSubCharacteristic = ruleToSubCharacteristic(ruleDoc); | |||
if (ruleSubCharacteristic != null) { | |||
ruleResponse.setDebtSubChar(ruleSubCharacteristic); | |||
String ruleSubCharacteristicName = ruleToSubCharacteristicName(ruleDoc, context); | |||
if (ruleSubCharacteristicName != null) { | |||
ruleResponse.setDebtSubCharName(ruleSubCharacteristicName); | |||
} | |||
} | |||
} | |||
private boolean needDebtCharacteristicNames(@Nullable QueryContext context) { | |||
return context == null || context.getFieldsToReturn().contains("debtCharName"); | |||
} | |||
private boolean needDebtSubCharacteristicNames(@Nullable QueryContext context) { | |||
return context == null || context.getFieldsToReturn().contains("debtSubCharName"); | |||
} | |||
@CheckForNull | |||
private static String ruleToCharacteristic(Rule rule) { | |||
String debtCharacteristicKey = rule.debtCharacteristicKey(); | |||
if (debtCharacteristicKey != null && !DebtCharacteristic.NONE.equals(debtCharacteristicKey)) { | |||
return debtCharacteristicKey; | |||
} | |||
return null; | |||
} | |||
@CheckForNull | |||
private static String ruleToSubCharacteristic(Rule rule) { | |||
String debtSubCharacteristicKey = rule.debtSubCharacteristicKey(); | |||
if (debtSubCharacteristicKey != null && !DebtCharacteristic.NONE.equals(debtSubCharacteristicKey)) { | |||
return debtSubCharacteristicKey; | |||
} | |||
return null; | |||
} | |||
private static String ruleToCharacteristicName(Rule rule, RuleMappingContext context) { | |||
return context.debtCharacteristicName(rule.debtCharacteristicKey()); | |||
} | |||
private static String ruleToSubCharacteristicName(Rule rule, RuleMappingContext context) { | |||
return context.debtCharacteristicName(rule.debtSubCharacteristicKey()); | |||
} | |||
private static boolean ruleToOverloaded(Rule rule) { | |||
return rule.debtOverloaded(); | |||
} | |||
private static class OverriddenMapper extends IndexMapper<RuleDoc, RuleMappingContext> { | |||
private OverriddenMapper() { | |||
super(RuleNormalizer.RuleField.CHARACTERISTIC_OVERLOADED.field(), | |||
RuleNormalizer.RuleField.SUB_CHARACTERISTIC_OVERLOADED.field(), | |||
RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE_OVERLOADED.field()); | |||
private static class SimpleMapper extends IndexMapper<RuleDoc, RuleMappingContext> { | |||
private SimpleMapper(String... fields) { | |||
super(fields); | |||
} | |||
@Override | |||
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { | |||
json.prop("debtOverloaded", rule.debtOverloaded()); | |||
public void write(JsonWriter json, RuleDoc doc, RuleMappingContext context) { | |||
// do not do anything | |||
} | |||
} | |||
private enum RuleParamToResponseRuleParam implements Function<RuleParam, Rules.Rule.Param> { | |||
INSTANCE; | |||
@Override | |||
public Rules.Rule.Param apply(@Nonnull RuleParam param) { | |||
Rules.Rule.Param.Builder paramResponse = Rules.Rule.Param.newBuilder(); | |||
paramResponse.setKey(param.key()); | |||
if (param.description() != null) { | |||
paramResponse.setHtmlDesc(Markdown.convertToHtml(param.description())); | |||
} | |||
if (param.defaultValue() != null) { | |||
paramResponse.setDefaultValue(param.defaultValue()); | |||
} | |||
if (param.type() != null) { | |||
paramResponse.setType(param.type().type()); | |||
} | |||
return paramResponse.build(); | |||
} | |||
} | |||
} | |||
@@ -276,10 +450,4 @@ class RuleMappingContext { | |||
debtCharacteristicNamesByKey.put(c.key(), c.name()); | |||
} | |||
} | |||
void addAll(Collection<DebtCharacteristic> coll) { | |||
for (DebtCharacteristic c : coll) { | |||
add(c); | |||
} | |||
} | |||
} |
@@ -41,7 +41,6 @@ import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.api.server.ws.WebService.Param; | |||
import org.sonar.api.utils.text.JsonWriter; | |||
import org.sonar.db.qualityprofile.QualityProfileDto; | |||
import org.sonar.server.qualityprofile.ActiveRule; | |||
import org.sonar.server.rule.Rule; | |||
@@ -54,6 +53,10 @@ import org.sonar.server.search.QueryContext; | |||
import org.sonar.server.search.Result; | |||
import org.sonar.server.search.ws.SearchOptions; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonarqube.ws.Common; | |||
import org.sonarqube.ws.Rules.SearchResponse; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
/** | |||
* @since 4.4 | |||
@@ -124,19 +127,24 @@ public class SearchAction implements RulesWsAction { | |||
RuleQuery query = doQuery(request); | |||
Result<Rule> result = doSearch(query, context); | |||
JsonWriter json = response.newJsonWriter().beginObject(); | |||
writeStatistics(json, result, context); | |||
doContextResponse(request, result, json); | |||
SearchResponse responseBuilder = buildResponse(request, context, result); | |||
writeProtobuf(responseBuilder, request, response); | |||
} | |||
private SearchResponse buildResponse(Request request, QueryContext context, Result<Rule> result) { | |||
SearchResponse.Builder responseBuilder = SearchResponse.newBuilder(); | |||
writeStatistics(responseBuilder, result, context); | |||
doContextResponse(request, result, responseBuilder); | |||
if (context.isFacet()) { | |||
writeFacets(request, context, result, json); | |||
writeFacets(responseBuilder, request, context, result); | |||
} | |||
json.endObject().close(); | |||
return responseBuilder.build(); | |||
} | |||
protected void writeStatistics(JsonWriter json, Result searchResult, QueryContext context) { | |||
json.prop("total", searchResult.getTotal()); | |||
json.prop(Param.PAGE, context.getPage()); | |||
json.prop(Param.PAGE_SIZE, context.getLimit()); | |||
protected void writeStatistics(SearchResponse.Builder response, Result searchResult, QueryContext context) { | |||
response.setTotal(searchResult.getTotal()); | |||
response.setP(context.getPage()); | |||
response.setPs(context.getLimit()); | |||
} | |||
protected void doDefinition(WebService.NewAction action) { | |||
@@ -299,12 +307,10 @@ public class SearchAction implements RulesWsAction { | |||
return query; | |||
} | |||
private void writeRules(Result<Rule> result, JsonWriter json, QueryContext context) { | |||
json.name("rules").beginArray(); | |||
private void writeRules(SearchResponse.Builder response, Result<Rule> result, QueryContext context) { | |||
for (Rule rule : result.getHits()) { | |||
mapping.write(rule, json, context); | |||
response.addRules(mapping.buildRuleResponse(rule, context)); | |||
} | |||
json.endArray(); | |||
} | |||
protected QueryContext getQueryContext(Request request) { | |||
@@ -355,12 +361,12 @@ public class SearchAction implements RulesWsAction { | |||
return plainQuery; | |||
} | |||
protected void doContextResponse(Request request, Result<Rule> result, JsonWriter json) { | |||
protected void doContextResponse(Request request, Result<Rule> result, SearchResponse.Builder response) { | |||
// TODO Get rid of this horrible hack: fields on request are not the same as fields for ES search ! 2/2 | |||
QueryContext contextForResponse = loadCommonContext(request); | |||
writeRules(result, json, contextForResponse); | |||
writeRules(response, result, contextForResponse); | |||
if (contextForResponse.getFieldsToReturn().contains("actives")) { | |||
activeRuleCompleter.completeSearch(doQuery(request), result.getHits(), json); | |||
activeRuleCompleter.completeSearch(doQuery(request), result.getHits(), response); | |||
} | |||
} | |||
@@ -370,7 +376,7 @@ public class SearchAction implements RulesWsAction { | |||
return builder.add("actives").build(); | |||
} | |||
protected void writeFacets(Request request, QueryContext context, Result<?> results, JsonWriter json) { | |||
protected void writeFacets(SearchResponse.Builder response, Request request, QueryContext context, Result<?> results) { | |||
addMandatoryFacetValues(results, RuleIndex.FACET_DEBT_CHARACTERISTICS, request.paramAsStrings(PARAM_DEBT_CHARACTERISTICS)); | |||
addMandatoryFacetValues(results, RuleIndex.FACET_LANGUAGES, request.paramAsStrings(PARAM_LANGUAGES)); | |||
addMandatoryFacetValues(results, RuleIndex.FACET_REPOSITORIES, request.paramAsStrings(PARAM_REPOSITORIES)); | |||
@@ -381,25 +387,23 @@ public class SearchAction implements RulesWsAction { | |||
mergeNoneAndEmptyBucketOnCharacteristics(results); | |||
json.name("facets").beginArray(); | |||
Common.Facet.Builder facet = Common.Facet.newBuilder(); | |||
Common.FacetValue.Builder value = Common.FacetValue.newBuilder(); | |||
for (String facetName : context.facets()) { | |||
json.beginObject(); | |||
json.prop("property", facetName); | |||
json.name("values").beginArray(); | |||
facet.clear().setProperty(facetName); | |||
if (results.getFacets().containsKey(facetName)) { | |||
Set<String> itemsFromFacets = Sets.newHashSet(); | |||
for (FacetValue facetValue : results.getFacets().get(facetName)) { | |||
itemsFromFacets.add(facetValue.getKey()); | |||
json.beginObject(); | |||
json.prop("val", facetValue.getKey()); | |||
json.prop("count", facetValue.getValue()); | |||
json.endObject(); | |||
facet.addValues(value | |||
.clear() | |||
.setVal(facetValue.getKey()) | |||
.setCount(facetValue.getValue())); | |||
} | |||
addZeroFacetsForSelectedItems(request, facetName, itemsFromFacets, json); | |||
addZeroFacetsForSelectedItems(facet, request, facetName, itemsFromFacets); | |||
} | |||
json.endArray().endObject(); | |||
response.getFacetsBuilder().addFacets(facet); | |||
} | |||
json.endArray(); | |||
} | |||
protected void mergeNoneAndEmptyBucketOnCharacteristics(Result<?> results) { | |||
@@ -424,15 +428,15 @@ public class SearchAction implements RulesWsAction { | |||
} | |||
} | |||
private static void addZeroFacetsForSelectedItems(Request request, String facetName, Set<String> itemsFromFacets, JsonWriter json) { | |||
private static void addZeroFacetsForSelectedItems(Common.Facet.Builder facet, Request request, String facetName, Set<String> itemsFromFacets) { | |||
List<String> requestParams = request.paramAsStrings(facetName); | |||
if (requestParams != null) { | |||
Common.FacetValue.Builder value = Common.FacetValue.newBuilder(); | |||
for (String param : requestParams) { | |||
if (!itemsFromFacets.contains(param)) { | |||
json.beginObject(); | |||
json.prop("val", param); | |||
json.prop("count", 0); | |||
json.endObject(); | |||
facet.addValues(value.clear() | |||
.setVal(param) | |||
.setCount(0L)); | |||
} | |||
} | |||
} |
@@ -24,10 +24,12 @@ import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.api.utils.text.JsonWriter; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.rule.Rule; | |||
import org.sonar.server.rule.RuleService; | |||
import org.sonarqube.ws.Rules.ShowResponse; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
/** | |||
* @since 4.4 | |||
@@ -70,19 +72,25 @@ public class ShowAction implements RulesWsAction { | |||
} | |||
@Override | |||
public void handle(Request request, Response response) { | |||
public void handle(Request request, Response response) throws Exception { | |||
RuleKey key = RuleKey.parse(request.mandatoryParam(PARAM_KEY)); | |||
Rule rule = service.getByKey(key); | |||
if (rule == null) { | |||
throw new NotFoundException("Rule not found: " + key); | |||
} | |||
JsonWriter json = response.newJsonWriter().beginObject().name("rule"); | |||
mapping.write(rule, json, null /* TODO replace by SearchOptions immutable constant */); | |||
ShowResponse showResponse = buildResponse(request, rule); | |||
writeProtobuf(showResponse, request, response); | |||
} | |||
private ShowResponse buildResponse(Request request, Rule rule) { | |||
ShowResponse.Builder responseBuilder = ShowResponse.newBuilder(); | |||
responseBuilder.setRule(mapping.buildRuleResponse(rule, null /* TODO replace by SearchOptions immutable constant */)); | |||
if (request.mandatoryParamAsBoolean(PARAM_ACTIVES)) { | |||
activeRuleCompleter.completeShow(rule, json); | |||
activeRuleCompleter.completeShow(rule, responseBuilder); | |||
} | |||
json.endObject().close(); | |||
return responseBuilder.build(); | |||
} | |||
} |
@@ -31,11 +31,13 @@ import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.api.utils.KeyValueFormat; | |||
import org.sonar.api.utils.text.JsonWriter; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.rule.Rule; | |||
import org.sonar.server.rule.RuleService; | |||
import org.sonar.server.rule.RuleUpdate; | |||
import org.sonarqube.ws.Rules.UpdateResponse; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
public class UpdateAction implements RulesWsAction { | |||
@@ -126,7 +128,9 @@ public class UpdateAction implements RulesWsAction { | |||
public void handle(Request request, Response response) throws Exception { | |||
RuleUpdate update = readRequest(request); | |||
service.update(update); | |||
writeResponse(response, update.getRuleKey()); | |||
UpdateResponse updateResponse = buildResponse(update.getRuleKey()); | |||
writeProtobuf(updateResponse, request, response); | |||
} | |||
private RuleUpdate readRequest(Request request) { | |||
@@ -211,10 +215,11 @@ public class UpdateAction implements RulesWsAction { | |||
} | |||
} | |||
private void writeResponse(Response response, RuleKey ruleKey) { | |||
private UpdateResponse buildResponse(RuleKey ruleKey) { | |||
Rule rule = service.getNonNullByKey(ruleKey); | |||
JsonWriter json = response.newJsonWriter().beginObject().name("rule"); | |||
mapping.write(rule, json, null /* TODO replace by SearchOptions immutable constant */); | |||
json.endObject().close(); | |||
UpdateResponse.Builder responseBuilder = UpdateResponse.newBuilder(); | |||
responseBuilder.setRule(mapping.buildRuleResponse(rule, null /* TODO replace by SearchOptions immutable constant */)); | |||
return responseBuilder.build(); | |||
} | |||
} |
@@ -67,13 +67,6 @@ public abstract class BaseMapping<DOC extends BaseDoc, CTX> { | |||
return result; | |||
} | |||
/** | |||
* Write all document fields | |||
*/ | |||
protected void doWrite(DOC doc, @Nullable CTX context, JsonWriter json) { | |||
doWrite(doc, context, json, null); | |||
} | |||
/** | |||
* Write only requested document fields | |||
*/ | |||
@@ -120,7 +113,7 @@ public abstract class BaseMapping<DOC extends BaseDoc, CTX> { | |||
return this; | |||
} | |||
public static interface Mapper<DOC extends BaseDoc, CTX> { | |||
public interface Mapper<DOC extends BaseDoc, CTX> { | |||
void write(JsonWriter json, DOC doc, CTX context); | |||
} | |||
@@ -142,11 +135,6 @@ public abstract class BaseMapping<DOC extends BaseDoc, CTX> { | |||
public static class IndexStringMapper<DOC extends BaseDoc, CTX> extends IndexMapper<DOC, CTX> { | |||
protected final String key; | |||
public IndexStringMapper(String key, String indexKey, String defaultIndexKey) { | |||
super(indexKey, defaultIndexKey); | |||
this.key = key; | |||
} | |||
public IndexStringMapper(String key, String indexKey) { | |||
super(indexKey); | |||
this.key = key; |
@@ -1,5 +1,7 @@ | |||
{ | |||
"total": 2, "p": 1, "ps": 100, | |||
"total": 2, | |||
"p": 1, | |||
"ps": 100, | |||
"rules": [ | |||
{ | |||
"key": "xoo:x2", | |||
@@ -10,6 +12,7 @@ | |||
{ | |||
"key": "xoo:x1", | |||
"name": "Rule x1", | |||
"htmlDesc": "Description x1", | |||
"htmlDesc": "Description x1" | |||
} | |||
]} | |||
] | |||
} |
@@ -184,7 +184,7 @@ | |||
<select id="selectEnabledFilesFromProject" parameterType="map" resultType="FilePathWithHash"> | |||
SELECT p.uuid, p.path, p.module_uuid as moduleUuid, fs.src_hash as srcHash | |||
FROM projects p | |||
INNER JOIN file_sources fs ON fs.file_uuid=p.uuid | |||
INNER JOIN file_sources fs ON fs.file_uuid=p.uuid and fs.data_type='SOURCE' | |||
<where> | |||
AND p.project_uuid=#{projectUuid} | |||
AND p.enabled=${_true} |
@@ -9,71 +9,61 @@ public final class QualityProfiles { | |||
com.google.protobuf.ExtensionRegistry registry) { | |||
} | |||
public interface WsSearchResponseOrBuilder extends | |||
// @@protoc_insertion_point(interface_extends:sonarqube.ws.rules.WsSearchResponse) | |||
// @@protoc_insertion_point(interface_extends:sonarqube.ws.qualityprofiles.WsSearchResponse) | |||
com.google.protobuf.MessageOrBuilder { | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
java.util.List<org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile> | |||
getProfilesList(); | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile getProfiles(int index); | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
int getProfilesCount(); | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
java.util.List<? extends org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfileOrBuilder> | |||
getProfilesOrBuilderList(); | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfileOrBuilder getProfilesOrBuilder( | |||
int index); | |||
} | |||
/** | |||
* Protobuf type {@code sonarqube.ws.rules.WsSearchResponse} | |||
* Protobuf type {@code sonarqube.ws.qualityprofiles.WsSearchResponse} | |||
* | |||
* <pre> | |||
* WS api/qualityprofiles/search | |||
* </pre> | |||
*/ | |||
public static final class WsSearchResponse extends | |||
public static final class WsSearchResponse extends | |||
com.google.protobuf.GeneratedMessage implements | |||
// @@protoc_insertion_point(message_implements:sonarqube.ws.rules.WsSearchResponse) | |||
// @@protoc_insertion_point(message_implements:sonarqube.ws.qualityprofiles.WsSearchResponse) | |||
WsSearchResponseOrBuilder { | |||
// Use WsSearchResponse.newBuilder() to construct. | |||
private WsSearchResponse(com.google.protobuf.GeneratedMessage.Builder<?> builder) { | |||
private WsSearchResponse(com.google.protobuf.GeneratedMessage.Builder builder) { | |||
super(builder); | |||
this.unknownFields = builder.getUnknownFields(); | |||
} | |||
private WsSearchResponse(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } | |||
private static final WsSearchResponse defaultInstance; | |||
public static WsSearchResponse getDefaultInstance() { | |||
return defaultInstance; | |||
} | |||
public WsSearchResponse getDefaultInstanceForType() { | |||
return defaultInstance; | |||
private WsSearchResponse() { | |||
profiles_ = java.util.Collections.emptyList(); | |||
} | |||
private final com.google.protobuf.UnknownFieldSet unknownFields; | |||
@java.lang.Override | |||
public final com.google.protobuf.UnknownFieldSet | |||
getUnknownFields() { | |||
getUnknownFields() { | |||
return this.unknownFields; | |||
} | |||
private WsSearchResponse( | |||
com.google.protobuf.CodedInputStream input, | |||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) | |||
throws com.google.protobuf.InvalidProtocolBufferException { | |||
initFields(); | |||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) { | |||
this(); | |||
int mutable_bitField0_ = 0; | |||
com.google.protobuf.UnknownFieldSet.Builder unknownFields = | |||
com.google.protobuf.UnknownFieldSet.newBuilder(); | |||
@@ -103,10 +93,11 @@ public final class QualityProfiles { | |||
} | |||
} | |||
} catch (com.google.protobuf.InvalidProtocolBufferException e) { | |||
throw e.setUnfinishedMessage(this); | |||
throw new RuntimeException(e.setUnfinishedMessage(this)); | |||
} catch (java.io.IOException e) { | |||
throw new com.google.protobuf.InvalidProtocolBufferException( | |||
e.getMessage()).setUnfinishedMessage(this); | |||
throw new RuntimeException( | |||
new com.google.protobuf.InvalidProtocolBufferException( | |||
e.getMessage()).setUnfinishedMessage(this)); | |||
} finally { | |||
if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) { | |||
profiles_ = java.util.Collections.unmodifiableList(profiles_); | |||
@@ -117,33 +108,18 @@ public final class QualityProfiles { | |||
} | |||
public static final com.google.protobuf.Descriptors.Descriptor | |||
getDescriptor() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_descriptor; | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_descriptor; | |||
} | |||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable | |||
internalGetFieldAccessorTable() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_fieldAccessorTable | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_fieldAccessorTable | |||
.ensureFieldAccessorsInitialized( | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.class, org.sonarqube.ws.QualityProfiles.WsSearchResponse.Builder.class); | |||
} | |||
public static com.google.protobuf.Parser<WsSearchResponse> PARSER = | |||
new com.google.protobuf.AbstractParser<WsSearchResponse>() { | |||
public WsSearchResponse parsePartialFrom( | |||
com.google.protobuf.CodedInputStream input, | |||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) | |||
throws com.google.protobuf.InvalidProtocolBufferException { | |||
return new WsSearchResponse(input, extensionRegistry); | |||
} | |||
}; | |||
@java.lang.Override | |||
public com.google.protobuf.Parser<WsSearchResponse> getParserForType() { | |||
return PARSER; | |||
} | |||
public interface QualityProfileOrBuilder extends | |||
// @@protoc_insertion_point(interface_extends:sonarqube.ws.rules.WsSearchResponse.QualityProfile) | |||
// @@protoc_insertion_point(interface_extends:sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile) | |||
com.google.protobuf.MessageOrBuilder { | |||
/** | |||
@@ -281,39 +257,39 @@ public final class QualityProfiles { | |||
getRulesUpdatedAtBytes(); | |||
} | |||
/** | |||
* Protobuf type {@code sonarqube.ws.rules.WsSearchResponse.QualityProfile} | |||
* Protobuf type {@code sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile} | |||
*/ | |||
public static final class QualityProfile extends | |||
public static final class QualityProfile extends | |||
com.google.protobuf.GeneratedMessage implements | |||
// @@protoc_insertion_point(message_implements:sonarqube.ws.rules.WsSearchResponse.QualityProfile) | |||
// @@protoc_insertion_point(message_implements:sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile) | |||
QualityProfileOrBuilder { | |||
// Use QualityProfile.newBuilder() to construct. | |||
private QualityProfile(com.google.protobuf.GeneratedMessage.Builder<?> builder) { | |||
private QualityProfile(com.google.protobuf.GeneratedMessage.Builder builder) { | |||
super(builder); | |||
this.unknownFields = builder.getUnknownFields(); | |||
} | |||
private QualityProfile(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } | |||
private static final QualityProfile defaultInstance; | |||
public static QualityProfile getDefaultInstance() { | |||
return defaultInstance; | |||
} | |||
public QualityProfile getDefaultInstanceForType() { | |||
return defaultInstance; | |||
private QualityProfile() { | |||
key_ = ""; | |||
name_ = ""; | |||
language_ = ""; | |||
languageName_ = ""; | |||
isInherited_ = false; | |||
parentKey_ = ""; | |||
parentName_ = ""; | |||
isDefault_ = false; | |||
activeRuleCount_ = 0L; | |||
projectCount_ = 0L; | |||
rulesUpdatedAt_ = ""; | |||
} | |||
private final com.google.protobuf.UnknownFieldSet unknownFields; | |||
@java.lang.Override | |||
public final com.google.protobuf.UnknownFieldSet | |||
getUnknownFields() { | |||
getUnknownFields() { | |||
return this.unknownFields; | |||
} | |||
private QualityProfile( | |||
com.google.protobuf.CodedInputStream input, | |||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) | |||
throws com.google.protobuf.InvalidProtocolBufferException { | |||
initFields(); | |||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) { | |||
this(); | |||
int mutable_bitField0_ = 0; | |||
com.google.protobuf.UnknownFieldSet.Builder unknownFields = | |||
com.google.protobuf.UnknownFieldSet.newBuilder(); | |||
@@ -397,10 +373,11 @@ public final class QualityProfiles { | |||
} | |||
} | |||
} catch (com.google.protobuf.InvalidProtocolBufferException e) { | |||
throw e.setUnfinishedMessage(this); | |||
throw new RuntimeException(e.setUnfinishedMessage(this)); | |||
} catch (java.io.IOException e) { | |||
throw new com.google.protobuf.InvalidProtocolBufferException( | |||
e.getMessage()).setUnfinishedMessage(this); | |||
throw new RuntimeException( | |||
new com.google.protobuf.InvalidProtocolBufferException( | |||
e.getMessage()).setUnfinishedMessage(this)); | |||
} finally { | |||
this.unknownFields = unknownFields.build(); | |||
makeExtensionsImmutable(); | |||
@@ -408,34 +385,19 @@ public final class QualityProfiles { | |||
} | |||
public static final com.google.protobuf.Descriptors.Descriptor | |||
getDescriptor() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_descriptor; | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_descriptor; | |||
} | |||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable | |||
internalGetFieldAccessorTable() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_fieldAccessorTable | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_fieldAccessorTable | |||
.ensureFieldAccessorsInitialized( | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.class, org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder.class); | |||
} | |||
public static com.google.protobuf.Parser<QualityProfile> PARSER = | |||
new com.google.protobuf.AbstractParser<QualityProfile>() { | |||
public QualityProfile parsePartialFrom( | |||
com.google.protobuf.CodedInputStream input, | |||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) | |||
throws com.google.protobuf.InvalidProtocolBufferException { | |||
return new QualityProfile(input, extensionRegistry); | |||
} | |||
}; | |||
@java.lang.Override | |||
public com.google.protobuf.Parser<QualityProfile> getParserForType() { | |||
return PARSER; | |||
} | |||
private int bitField0_; | |||
public static final int KEY_FIELD_NUMBER = 1; | |||
private java.lang.Object key_; | |||
private volatile java.lang.Object key_; | |||
/** | |||
* <code>optional string key = 1;</code> | |||
*/ | |||
@@ -477,7 +439,7 @@ public final class QualityProfiles { | |||
} | |||
public static final int NAME_FIELD_NUMBER = 2; | |||
private java.lang.Object name_; | |||
private volatile java.lang.Object name_; | |||
/** | |||
* <code>optional string name = 2;</code> | |||
*/ | |||
@@ -519,7 +481,7 @@ public final class QualityProfiles { | |||
} | |||
public static final int LANGUAGE_FIELD_NUMBER = 3; | |||
private java.lang.Object language_; | |||
private volatile java.lang.Object language_; | |||
/** | |||
* <code>optional string language = 3;</code> | |||
*/ | |||
@@ -561,7 +523,7 @@ public final class QualityProfiles { | |||
} | |||
public static final int LANGUAGENAME_FIELD_NUMBER = 4; | |||
private java.lang.Object languageName_; | |||
private volatile java.lang.Object languageName_; | |||
/** | |||
* <code>optional string languageName = 4;</code> | |||
*/ | |||
@@ -618,7 +580,7 @@ public final class QualityProfiles { | |||
} | |||
public static final int PARENTKEY_FIELD_NUMBER = 6; | |||
private java.lang.Object parentKey_; | |||
private volatile java.lang.Object parentKey_; | |||
/** | |||
* <code>optional string parentKey = 6;</code> | |||
*/ | |||
@@ -660,7 +622,7 @@ public final class QualityProfiles { | |||
} | |||
public static final int PARENTNAME_FIELD_NUMBER = 7; | |||
private java.lang.Object parentName_; | |||
private volatile java.lang.Object parentName_; | |||
/** | |||
* <code>optional string parentName = 7;</code> | |||
*/ | |||
@@ -747,7 +709,7 @@ public final class QualityProfiles { | |||
} | |||
public static final int RULESUPDATEDAT_FIELD_NUMBER = 11; | |||
private java.lang.Object rulesUpdatedAt_; | |||
private volatile java.lang.Object rulesUpdatedAt_; | |||
/** | |||
* <code>optional string rulesUpdatedAt = 11;</code> | |||
*/ | |||
@@ -788,19 +750,6 @@ public final class QualityProfiles { | |||
} | |||
} | |||
private void initFields() { | |||
key_ = ""; | |||
name_ = ""; | |||
language_ = ""; | |||
languageName_ = ""; | |||
isInherited_ = false; | |||
parentKey_ = ""; | |||
parentName_ = ""; | |||
isDefault_ = false; | |||
activeRuleCount_ = 0L; | |||
projectCount_ = 0L; | |||
rulesUpdatedAt_ = ""; | |||
} | |||
private byte memoizedIsInitialized = -1; | |||
public final boolean isInitialized() { | |||
byte isInitialized = memoizedIsInitialized; | |||
@@ -813,7 +762,6 @@ public final class QualityProfiles { | |||
public void writeTo(com.google.protobuf.CodedOutputStream output) | |||
throws java.io.IOException { | |||
getSerializedSize(); | |||
if (((bitField0_ & 0x00000001) == 0x00000001)) { | |||
output.writeBytes(1, getKeyBytes()); | |||
} | |||
@@ -847,7 +795,7 @@ public final class QualityProfiles { | |||
if (((bitField0_ & 0x00000400) == 0x00000400)) { | |||
output.writeBytes(11, getRulesUpdatedAtBytes()); | |||
} | |||
getUnknownFields().writeTo(output); | |||
unknownFields.writeTo(output); | |||
} | |||
private int memoizedSerializedSize = -1; | |||
@@ -900,18 +848,12 @@ public final class QualityProfiles { | |||
size += com.google.protobuf.CodedOutputStream | |||
.computeBytesSize(11, getRulesUpdatedAtBytes()); | |||
} | |||
size += getUnknownFields().getSerializedSize(); | |||
size += unknownFields.getSerializedSize(); | |||
memoizedSerializedSize = size; | |||
return size; | |||
} | |||
private static final long serialVersionUID = 0L; | |||
@java.lang.Override | |||
protected java.lang.Object writeReplace() | |||
throws java.io.ObjectStreamException { | |||
return super.writeReplace(); | |||
} | |||
public static org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile parseFrom( | |||
com.google.protobuf.ByteString data) | |||
throws com.google.protobuf.InvalidProtocolBufferException { | |||
@@ -965,12 +907,17 @@ public final class QualityProfiles { | |||
return PARSER.parseFrom(input, extensionRegistry); | |||
} | |||
public static Builder newBuilder() { return Builder.create(); } | |||
public Builder newBuilderForType() { return newBuilder(); } | |||
public static Builder newBuilder() { | |||
return DEFAULT_INSTANCE.toBuilder(); | |||
} | |||
public static Builder newBuilder(org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile prototype) { | |||
return newBuilder().mergeFrom(prototype); | |||
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); | |||
} | |||
public Builder toBuilder() { | |||
return this == DEFAULT_INSTANCE | |||
? new Builder() : new Builder().mergeFrom(this); | |||
} | |||
public Builder toBuilder() { return newBuilder(this); } | |||
@java.lang.Override | |||
protected Builder newBuilderForType( | |||
@@ -979,20 +926,20 @@ public final class QualityProfiles { | |||
return builder; | |||
} | |||
/** | |||
* Protobuf type {@code sonarqube.ws.rules.WsSearchResponse.QualityProfile} | |||
* Protobuf type {@code sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile} | |||
*/ | |||
public static final class Builder extends | |||
com.google.protobuf.GeneratedMessage.Builder<Builder> implements | |||
// @@protoc_insertion_point(builder_implements:sonarqube.ws.rules.WsSearchResponse.QualityProfile) | |||
// @@protoc_insertion_point(builder_implements:sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile) | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfileOrBuilder { | |||
public static final com.google.protobuf.Descriptors.Descriptor | |||
getDescriptor() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_descriptor; | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_descriptor; | |||
} | |||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable | |||
internalGetFieldAccessorTable() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_fieldAccessorTable | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_fieldAccessorTable | |||
.ensureFieldAccessorsInitialized( | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.class, org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder.class); | |||
} | |||
@@ -1011,10 +958,6 @@ public final class QualityProfiles { | |||
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { | |||
} | |||
} | |||
private static Builder create() { | |||
return new Builder(); | |||
} | |||
public Builder clear() { | |||
super.clear(); | |||
key_ = ""; | |||
@@ -1042,13 +985,9 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
public Builder clone() { | |||
return create().mergeFrom(buildPartial()); | |||
} | |||
public com.google.protobuf.Descriptors.Descriptor | |||
getDescriptorForType() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_descriptor; | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_descriptor; | |||
} | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile getDefaultInstanceForType() { | |||
@@ -1174,7 +1113,8 @@ public final class QualityProfiles { | |||
rulesUpdatedAt_ = other.rulesUpdatedAt_; | |||
onChanged(); | |||
} | |||
this.mergeUnknownFields(other.getUnknownFields()); | |||
this.mergeUnknownFields(other.unknownFields); | |||
onChanged(); | |||
return this; | |||
} | |||
@@ -1861,55 +1801,84 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
// @@protoc_insertion_point(builder_scope:sonarqube.ws.rules.WsSearchResponse.QualityProfile) | |||
// @@protoc_insertion_point(builder_scope:sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile) | |||
} | |||
// @@protoc_insertion_point(class_scope:sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile) | |||
private static final org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile DEFAULT_INSTANCE; | |||
static { | |||
defaultInstance = new QualityProfile(true); | |||
defaultInstance.initFields(); | |||
DEFAULT_INSTANCE = new org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile(); | |||
} | |||
public static org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile getDefaultInstance() { | |||
return DEFAULT_INSTANCE; | |||
} | |||
public static final com.google.protobuf.Parser<QualityProfile> PARSER = | |||
new com.google.protobuf.AbstractParser<QualityProfile>() { | |||
public QualityProfile parsePartialFrom( | |||
com.google.protobuf.CodedInputStream input, | |||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) | |||
throws com.google.protobuf.InvalidProtocolBufferException { | |||
try { | |||
return new QualityProfile(input, extensionRegistry); | |||
} catch (RuntimeException e) { | |||
if (e.getCause() instanceof | |||
com.google.protobuf.InvalidProtocolBufferException) { | |||
throw (com.google.protobuf.InvalidProtocolBufferException) | |||
e.getCause(); | |||
} | |||
throw e; | |||
} | |||
} | |||
}; | |||
@java.lang.Override | |||
public com.google.protobuf.Parser<QualityProfile> getParserForType() { | |||
return PARSER; | |||
} | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile getDefaultInstanceForType() { | |||
return DEFAULT_INSTANCE; | |||
} | |||
// @@protoc_insertion_point(class_scope:sonarqube.ws.rules.WsSearchResponse.QualityProfile) | |||
} | |||
public static final int PROFILES_FIELD_NUMBER = 1; | |||
private java.util.List<org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile> profiles_; | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public java.util.List<org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile> getProfilesList() { | |||
return profiles_; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public java.util.List<? extends org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfileOrBuilder> | |||
getProfilesOrBuilderList() { | |||
return profiles_; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public int getProfilesCount() { | |||
return profiles_.size(); | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile getProfiles(int index) { | |||
return profiles_.get(index); | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfileOrBuilder getProfilesOrBuilder( | |||
int index) { | |||
return profiles_.get(index); | |||
} | |||
private void initFields() { | |||
profiles_ = java.util.Collections.emptyList(); | |||
} | |||
private byte memoizedIsInitialized = -1; | |||
public final boolean isInitialized() { | |||
byte isInitialized = memoizedIsInitialized; | |||
@@ -1922,11 +1891,10 @@ public final class QualityProfiles { | |||
public void writeTo(com.google.protobuf.CodedOutputStream output) | |||
throws java.io.IOException { | |||
getSerializedSize(); | |||
for (int i = 0; i < profiles_.size(); i++) { | |||
output.writeMessage(1, profiles_.get(i)); | |||
} | |||
getUnknownFields().writeTo(output); | |||
unknownFields.writeTo(output); | |||
} | |||
private int memoizedSerializedSize = -1; | |||
@@ -1939,18 +1907,12 @@ public final class QualityProfiles { | |||
size += com.google.protobuf.CodedOutputStream | |||
.computeMessageSize(1, profiles_.get(i)); | |||
} | |||
size += getUnknownFields().getSerializedSize(); | |||
size += unknownFields.getSerializedSize(); | |||
memoizedSerializedSize = size; | |||
return size; | |||
} | |||
private static final long serialVersionUID = 0L; | |||
@java.lang.Override | |||
protected java.lang.Object writeReplace() | |||
throws java.io.ObjectStreamException { | |||
return super.writeReplace(); | |||
} | |||
public static org.sonarqube.ws.QualityProfiles.WsSearchResponse parseFrom( | |||
com.google.protobuf.ByteString data) | |||
throws com.google.protobuf.InvalidProtocolBufferException { | |||
@@ -2004,12 +1966,17 @@ public final class QualityProfiles { | |||
return PARSER.parseFrom(input, extensionRegistry); | |||
} | |||
public static Builder newBuilder() { return Builder.create(); } | |||
public Builder newBuilderForType() { return newBuilder(); } | |||
public static Builder newBuilder() { | |||
return DEFAULT_INSTANCE.toBuilder(); | |||
} | |||
public static Builder newBuilder(org.sonarqube.ws.QualityProfiles.WsSearchResponse prototype) { | |||
return newBuilder().mergeFrom(prototype); | |||
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); | |||
} | |||
public Builder toBuilder() { | |||
return this == DEFAULT_INSTANCE | |||
? new Builder() : new Builder().mergeFrom(this); | |||
} | |||
public Builder toBuilder() { return newBuilder(this); } | |||
@java.lang.Override | |||
protected Builder newBuilderForType( | |||
@@ -2018,7 +1985,7 @@ public final class QualityProfiles { | |||
return builder; | |||
} | |||
/** | |||
* Protobuf type {@code sonarqube.ws.rules.WsSearchResponse} | |||
* Protobuf type {@code sonarqube.ws.qualityprofiles.WsSearchResponse} | |||
* | |||
* <pre> | |||
* WS api/qualityprofiles/search | |||
@@ -2026,16 +1993,16 @@ public final class QualityProfiles { | |||
*/ | |||
public static final class Builder extends | |||
com.google.protobuf.GeneratedMessage.Builder<Builder> implements | |||
// @@protoc_insertion_point(builder_implements:sonarqube.ws.rules.WsSearchResponse) | |||
// @@protoc_insertion_point(builder_implements:sonarqube.ws.qualityprofiles.WsSearchResponse) | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponseOrBuilder { | |||
public static final com.google.protobuf.Descriptors.Descriptor | |||
getDescriptor() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_descriptor; | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_descriptor; | |||
} | |||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable | |||
internalGetFieldAccessorTable() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_fieldAccessorTable | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_fieldAccessorTable | |||
.ensureFieldAccessorsInitialized( | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.class, org.sonarqube.ws.QualityProfiles.WsSearchResponse.Builder.class); | |||
} | |||
@@ -2055,10 +2022,6 @@ public final class QualityProfiles { | |||
getProfilesFieldBuilder(); | |||
} | |||
} | |||
private static Builder create() { | |||
return new Builder(); | |||
} | |||
public Builder clear() { | |||
super.clear(); | |||
if (profilesBuilder_ == null) { | |||
@@ -2070,13 +2033,9 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
public Builder clone() { | |||
return create().mergeFrom(buildPartial()); | |||
} | |||
public com.google.protobuf.Descriptors.Descriptor | |||
getDescriptorForType() { | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_rules_WsSearchResponse_descriptor; | |||
return org.sonarqube.ws.QualityProfiles.internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_descriptor; | |||
} | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse getDefaultInstanceForType() { | |||
@@ -2144,7 +2103,8 @@ public final class QualityProfiles { | |||
} | |||
} | |||
} | |||
this.mergeUnknownFields(other.getUnknownFields()); | |||
this.mergeUnknownFields(other.unknownFields); | |||
onChanged(); | |||
return this; | |||
} | |||
@@ -2184,7 +2144,7 @@ public final class QualityProfiles { | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile, org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder, org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfileOrBuilder> profilesBuilder_; | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public java.util.List<org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile> getProfilesList() { | |||
if (profilesBuilder_ == null) { | |||
@@ -2194,7 +2154,7 @@ public final class QualityProfiles { | |||
} | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public int getProfilesCount() { | |||
if (profilesBuilder_ == null) { | |||
@@ -2204,7 +2164,7 @@ public final class QualityProfiles { | |||
} | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile getProfiles(int index) { | |||
if (profilesBuilder_ == null) { | |||
@@ -2214,7 +2174,7 @@ public final class QualityProfiles { | |||
} | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public Builder setProfiles( | |||
int index, org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile value) { | |||
@@ -2231,7 +2191,7 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public Builder setProfiles( | |||
int index, org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder builderForValue) { | |||
@@ -2245,7 +2205,7 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public Builder addProfiles(org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile value) { | |||
if (profilesBuilder_ == null) { | |||
@@ -2261,7 +2221,7 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public Builder addProfiles( | |||
int index, org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile value) { | |||
@@ -2278,7 +2238,7 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public Builder addProfiles( | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder builderForValue) { | |||
@@ -2292,7 +2252,7 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public Builder addProfiles( | |||
int index, org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder builderForValue) { | |||
@@ -2306,7 +2266,7 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public Builder addAllProfiles( | |||
java.lang.Iterable<? extends org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile> values) { | |||
@@ -2321,7 +2281,7 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public Builder clearProfiles() { | |||
if (profilesBuilder_ == null) { | |||
@@ -2334,7 +2294,7 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public Builder removeProfiles(int index) { | |||
if (profilesBuilder_ == null) { | |||
@@ -2347,14 +2307,14 @@ public final class QualityProfiles { | |||
return this; | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder getProfilesBuilder( | |||
int index) { | |||
return getProfilesFieldBuilder().getBuilder(index); | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfileOrBuilder getProfilesOrBuilder( | |||
int index) { | |||
@@ -2364,7 +2324,7 @@ public final class QualityProfiles { | |||
} | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public java.util.List<? extends org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfileOrBuilder> | |||
getProfilesOrBuilderList() { | |||
@@ -2375,14 +2335,14 @@ public final class QualityProfiles { | |||
} | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder addProfilesBuilder() { | |||
return getProfilesFieldBuilder().addBuilder( | |||
org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.getDefaultInstance()); | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder addProfilesBuilder( | |||
int index) { | |||
@@ -2390,7 +2350,7 @@ public final class QualityProfiles { | |||
index, org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.getDefaultInstance()); | |||
} | |||
/** | |||
* <code>repeated .sonarqube.ws.rules.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
* <code>repeated .sonarqube.ws.qualityprofiles.WsSearchResponse.QualityProfile profiles = 1;</code> | |||
*/ | |||
public java.util.List<org.sonarqube.ws.QualityProfiles.WsSearchResponse.QualityProfile.Builder> | |||
getProfilesBuilderList() { | |||
@@ -2411,27 +2371,59 @@ public final class QualityProfiles { | |||
return profilesBuilder_; | |||
} | |||
// @@protoc_insertion_point(builder_scope:sonarqube.ws.rules.WsSearchResponse) | |||
// @@protoc_insertion_point(builder_scope:sonarqube.ws.qualityprofiles.WsSearchResponse) | |||
} | |||
// @@protoc_insertion_point(class_scope:sonarqube.ws.qualityprofiles.WsSearchResponse) | |||
private static final org.sonarqube.ws.QualityProfiles.WsSearchResponse DEFAULT_INSTANCE; | |||
static { | |||
defaultInstance = new WsSearchResponse(true); | |||
defaultInstance.initFields(); | |||
DEFAULT_INSTANCE = new org.sonarqube.ws.QualityProfiles.WsSearchResponse(); | |||
} | |||
public static org.sonarqube.ws.QualityProfiles.WsSearchResponse getDefaultInstance() { | |||
return DEFAULT_INSTANCE; | |||
} | |||
public static final com.google.protobuf.Parser<WsSearchResponse> PARSER = | |||
new com.google.protobuf.AbstractParser<WsSearchResponse>() { | |||
public WsSearchResponse parsePartialFrom( | |||
com.google.protobuf.CodedInputStream input, | |||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) | |||
throws com.google.protobuf.InvalidProtocolBufferException { | |||
try { | |||
return new WsSearchResponse(input, extensionRegistry); | |||
} catch (RuntimeException e) { | |||
if (e.getCause() instanceof | |||
com.google.protobuf.InvalidProtocolBufferException) { | |||
throw (com.google.protobuf.InvalidProtocolBufferException) | |||
e.getCause(); | |||
} | |||
throw e; | |||
} | |||
} | |||
}; | |||
@java.lang.Override | |||
public com.google.protobuf.Parser<WsSearchResponse> getParserForType() { | |||
return PARSER; | |||
} | |||
public org.sonarqube.ws.QualityProfiles.WsSearchResponse getDefaultInstanceForType() { | |||
return DEFAULT_INSTANCE; | |||
} | |||
// @@protoc_insertion_point(class_scope:sonarqube.ws.rules.WsSearchResponse) | |||
} | |||
private static final com.google.protobuf.Descriptors.Descriptor | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_descriptor; | |||
private static com.google.protobuf.Descriptors.Descriptor | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_descriptor; | |||
private static | |||
com.google.protobuf.GeneratedMessage.FieldAccessorTable | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_fieldAccessorTable; | |||
private static final com.google.protobuf.Descriptors.Descriptor | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_descriptor; | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_fieldAccessorTable; | |||
private static com.google.protobuf.Descriptors.Descriptor | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_descriptor; | |||
private static | |||
com.google.protobuf.GeneratedMessage.FieldAccessorTable | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_fieldAccessorTable; | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_fieldAccessorTable; | |||
public static com.google.protobuf.Descriptors.FileDescriptor | |||
getDescriptor() { | |||
@@ -2441,17 +2433,17 @@ public final class QualityProfiles { | |||
descriptor; | |||
static { | |||
java.lang.String[] descriptorData = { | |||
"\n\030ws-qualityprofiles.proto\022\022sonarqube.ws" + | |||
".rules\"\305\002\n\020WsSearchResponse\022E\n\010profiles\030" + | |||
"\001 \003(\01323.sonarqube.ws.rules.WsSearchRespo" + | |||
"nse.QualityProfile\032\351\001\n\016QualityProfile\022\013\n" + | |||
"\003key\030\001 \001(\t\022\014\n\004name\030\002 \001(\t\022\020\n\010language\030\003 \001" + | |||
"(\t\022\024\n\014languageName\030\004 \001(\t\022\023\n\013isInherited\030" + | |||
"\005 \001(\010\022\021\n\tparentKey\030\006 \001(\t\022\022\n\nparentName\030\007" + | |||
" \001(\t\022\021\n\tisDefault\030\010 \001(\010\022\027\n\017activeRuleCou" + | |||
"nt\030\t \001(\003\022\024\n\014projectCount\030\n \001(\003\022\026\n\016rulesU" + | |||
"pdatedAt\030\013 \001(\tB%\n\020org.sonarqube.wsB\017Qual", | |||
"ityProfilesH\001" | |||
"\n\030ws-qualityprofiles.proto\022\034sonarqube.ws" + | |||
".qualityprofiles\"\317\002\n\020WsSearchResponse\022O\n" + | |||
"\010profiles\030\001 \003(\0132=.sonarqube.ws.qualitypr" + | |||
"ofiles.WsSearchResponse.QualityProfile\032\351" + | |||
"\001\n\016QualityProfile\022\013\n\003key\030\001 \001(\t\022\014\n\004name\030\002" + | |||
" \001(\t\022\020\n\010language\030\003 \001(\t\022\024\n\014languageName\030\004" + | |||
" \001(\t\022\023\n\013isInherited\030\005 \001(\010\022\021\n\tparentKey\030\006" + | |||
" \001(\t\022\022\n\nparentName\030\007 \001(\t\022\021\n\tisDefault\030\010 " + | |||
"\001(\010\022\027\n\017activeRuleCount\030\t \001(\003\022\024\n\014projectC" + | |||
"ount\030\n \001(\003\022\026\n\016rulesUpdatedAt\030\013 \001(\tB%\n\020or", | |||
"g.sonarqube.wsB\017QualityProfilesH\001" | |||
}; | |||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = | |||
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { | |||
@@ -2465,17 +2457,17 @@ public final class QualityProfiles { | |||
.internalBuildGeneratedFileFrom(descriptorData, | |||
new com.google.protobuf.Descriptors.FileDescriptor[] { | |||
}, assigner); | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_descriptor = | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_descriptor = | |||
getDescriptor().getMessageTypes().get(0); | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_fieldAccessorTable = new | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_fieldAccessorTable = new | |||
com.google.protobuf.GeneratedMessage.FieldAccessorTable( | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_descriptor, | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_descriptor, | |||
new java.lang.String[] { "Profiles", }); | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_descriptor = | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_descriptor.getNestedTypes().get(0); | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_fieldAccessorTable = new | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_descriptor = | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_descriptor.getNestedTypes().get(0); | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_fieldAccessorTable = new | |||
com.google.protobuf.GeneratedMessage.FieldAccessorTable( | |||
internal_static_sonarqube_ws_rules_WsSearchResponse_QualityProfile_descriptor, | |||
internal_static_sonarqube_ws_qualityprofiles_WsSearchResponse_QualityProfile_descriptor, | |||
new java.lang.String[] { "Key", "Name", "Language", "LanguageName", "IsInherited", "ParentKey", "ParentName", "IsDefault", "ActiveRuleCount", "ProjectCount", "RulesUpdatedAt", }); | |||
} | |||
@@ -18,12 +18,10 @@ | |||
syntax = "proto2"; | |||
package sonarqube.ws.rules; | |||
package sonarqube.ws.qualityprofiles; | |||
option java_package = "org.sonarqube.ws"; | |||
option java_outer_classname = "QualityProfiles"; | |||
option optimize_for = SPEED; | |||
// WS api/qualityprofiles/search |
@@ -20,6 +20,8 @@ syntax = "proto2"; | |||
package sonarqube.ws.rules; | |||
import "ws-commons.proto"; | |||
option java_package = "org.sonarqube.ws"; | |||
option java_outer_classname = "Rules"; | |||
option optimize_for = SPEED; | |||
@@ -35,5 +37,119 @@ message ListResponse { | |||
} | |||
repeated Rule rules = 1; | |||
} | |||
// WS api/rules/search | |||
message SearchResponse { | |||
optional int64 total = 1; | |||
optional int32 p = 2; | |||
optional int64 ps = 3; | |||
repeated Rule rules = 4; | |||
optional Actives actives = 5; | |||
optional QProfiles qProfiles = 6; | |||
optional sonarqube.ws.commons.Facets facets = 7; | |||
} | |||
//WS api/rules/show | |||
message ShowResponse { | |||
optional Rule rule = 1; | |||
repeated Active actives = 3; | |||
} | |||
//WS api/rules/create | |||
message CreateResponse { | |||
optional Rule rule = 1; | |||
} | |||
//WS api/rules/update | |||
message UpdateResponse { | |||
optional Rule rule = 1; | |||
} | |||
message Rule { | |||
optional string key = 1; | |||
optional string repo = 2; | |||
optional string name = 3; | |||
optional string createdAt = 4; | |||
optional string htmlDesc = 5; | |||
optional string htmlNote = 6; | |||
optional string mdDesc = 7; | |||
optional string mdNote = 8; | |||
optional string noteLogin = 9; | |||
optional string severity = 10; | |||
optional sonarqube.ws.commons.RuleStatus status = 11; | |||
optional string internalKey = 12; | |||
optional bool isTemplate = 13; | |||
optional string templateKey = 14; | |||
optional Tags tags = 15; | |||
optional SysTags sysTags = 16; | |||
optional string lang = 19; | |||
optional string langName = 20; | |||
optional Params params = 21; | |||
// debt fields | |||
optional string defaultDebtChar = 23; | |||
optional string defaultDebtSubChar = 24; | |||
optional string debtChar = 25; | |||
optional string debtSubChar = 26; | |||
optional string debtCharName = 27; | |||
optional string debtSubCharName = 28; | |||
optional string defaultDebtRemFnType = 29; | |||
optional string defaultDebtRemFnCoeff = 30; | |||
optional string defaultDebtRemFnOffset = 31; | |||
optional string effortToFixDescription = 32; | |||
optional bool debtOverloaded = 33; | |||
optional string debtRemFnType = 34; | |||
optional string debtRemFnCoeff = 35; | |||
optional string debtRemFnOffset = 36; | |||
message Params { | |||
repeated Param params = 1; | |||
} | |||
message Param { | |||
optional string key = 1; | |||
optional string htmlDesc = 2; | |||
optional string defaultValue = 3; | |||
optional string type = 4; | |||
} | |||
} | |||
message SysTags { | |||
repeated string sysTags = 1; | |||
} | |||
message Tags { | |||
repeated string tags = 1; | |||
} | |||
message Actives { | |||
map<string, ActiveList> actives = 1; | |||
} | |||
message ActiveList { | |||
repeated Active activeList = 1; | |||
} | |||
message Active { | |||
optional string qProfile = 1; | |||
optional string inherit = 2; | |||
optional string severity = 3; | |||
optional string parent = 4; | |||
repeated Param params = 5; | |||
message Param { | |||
optional string key = 1; | |||
optional string value = 2; | |||
} | |||
} | |||
message QProfiles { | |||
map<string,QProfile> qProfiles = 1; | |||
} | |||
message QProfile { | |||
optional string name = 1; | |||
optional string lang = 2; | |||
optional string langName = 3; | |||
optional string parent = 4; | |||
} |