Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/ProjectFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* SonarQube, open source software quality management tool. | ||
* Copyright (C) 2008-2014 SonarSource | ||
* mailto:contact AT sonarsource DOT com | ||
* | ||
* SonarQube is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* SonarQube is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package org.sonar.server.measure.custom.ws; | ||
|
||
import org.sonar.api.server.ws.Request; | ||
import org.sonar.core.component.ComponentDto; | ||
import org.sonar.core.persistence.DbSession; | ||
import org.sonar.server.db.DbClient; | ||
import org.sonar.server.exceptions.NotFoundException; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
class ProjectFinder { | ||
private ProjectFinder() { | ||
// utility class | ||
} | ||
|
||
static ComponentDto searchProject(DbSession dbSession, DbClient dbClient, Request request) { | ||
String projectUuid = request.param(CreateAction.PARAM_PROJECT_ID); | ||
String projectKey = request.param(CreateAction.PARAM_PROJECT_KEY); | ||
checkArgument(projectUuid != null ^ projectKey != null, "The project key or the project id must be provided, not both."); | ||
|
||
if (projectUuid != null) { | ||
ComponentDto project = dbClient.componentDao().selectNullableByUuid(dbSession, projectUuid); | ||
if (project == null) { | ||
throw new NotFoundException(String.format("Project id '%s' not found", projectUuid)); | ||
} | ||
|
||
return project; | ||
} | ||
|
||
ComponentDto project = dbClient.componentDao().selectNullableByKey(dbSession, projectKey); | ||
if (project == null) { | ||
throw new NotFoundException(String.format("Project key '%s' not found", projectKey)); | ||
} | ||
|
||
return project; | ||
} | ||
|
||
} |