001/*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019 */
020
021package org.sonar.wsclient.services;
022
023import java.util.*;
024
025/**
026 * @since 2.7
027 */
028public class Profile extends Model {
029
030  private String language;
031  private String name;
032  private boolean defaultProfile;
033  private String parentName;
034  private List<Rule> rules = new ArrayList<Rule>();
035
036  public String getLanguage() {
037    return language;
038  }
039
040  public Profile setLanguage(String s) {
041    this.language = s;
042    return this;
043  }
044
045  public String getName() {
046    return name;
047  }
048
049  public Profile setName(String name) {
050    this.name = name;
051    return this;
052  }
053
054  public boolean isDefaultProfile() {
055    return defaultProfile;
056  }
057
058  public Profile setDefaultProfile(boolean b) {
059    this.defaultProfile = b;
060    return this;
061  }
062
063  public String getParentName() {
064    return parentName;
065  }
066
067  public Profile setParentName(String s) {
068    this.parentName = s;
069    return this;
070  }
071
072  public List<Rule> getRules() {
073    return rules;
074  }
075
076  public Rule getRule(String repositoryKey, String ruleKey) {
077    for (Rule rule : rules) {
078      if (repositoryKey.equals(rule.getRepository()) && ruleKey.equals(rule.getKey())) {
079        return rule;
080      }
081    }
082    return null;
083  }
084
085  public Profile addRule(Rule rule) {
086    rules.add(rule);
087    return this;
088  }
089
090  public static final class Rule {
091    private String key;
092    private String repository;
093    private String severity;
094    private String inheritance;
095    private Map<String,String> parameters;
096
097    public String getKey() {
098      return key;
099    }
100
101    public Rule setKey(String key) {
102      this.key = key;
103      return this;
104    }
105
106    public String getRepository() {
107      return repository;
108    }
109
110    public Rule setRepository(String repository) {
111      this.repository = repository;
112      return this;
113    }
114
115    public String getSeverity() {
116      return severity;
117    }
118
119    public Rule setSeverity(String severity) {
120      this.severity = severity;
121      return this;
122    }
123
124    public String getInheritance() {
125      return inheritance;
126    }
127
128    public Rule setInheritance(String inheritance) {
129      this.inheritance = inheritance;
130      return this;
131    }
132
133    public Map<String, String> getParameters() {
134      if (parameters==null) {
135        return Collections.emptyMap();
136      }
137      return parameters;
138    }
139
140    public String getParameter(String key) {
141      return getParameters().get(key);
142    }
143
144    public Rule addParameter(String key, String value) {
145      if (parameters==null) {
146        parameters = new HashMap<String,String>();
147      }
148      parameters.put(key, value);
149      return this;
150    }
151  }
152}