Browse Source

SONAR-8465 Create WS api/project_analyses/delete_event

tags/6.3-RC1
Teryk Bellahsene 7 years ago
parent
commit
637a056d41
19 changed files with 431 additions and 46 deletions
  1. 3
    1
      server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ProjectAnalysisModule.java
  2. 5
    5
      server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java
  3. 111
    0
      server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/DeleteEventAction.java
  4. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ProjectAnalysisModuleTest.java
  5. 2
    2
      server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/CreateEventActionTest.java
  6. 164
    0
      server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/DeleteEventActionTest.java
  7. 1
    1
      sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java
  8. 2
    1
      sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java
  9. 10
    1
      sonar-db/src/main/java/org/sonar/db/event/EventDao.java
  10. 5
    1
      sonar-db/src/main/java/org/sonar/db/event/EventMapper.java
  11. 14
    1
      sonar-db/src/main/resources/org/sonar/db/event/EventMapper.xml
  12. 0
    1
      sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
  13. 25
    1
      sonar-db/src/test/java/org/sonar/db/event/EventDaoTest.java
  14. 1
    1
      sonar-db/src/test/java/org/sonar/db/event/EventTesting.java
  15. 4
    27
      sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequest.java
  16. 35
    0
      sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/DeleteEventRequest.java
  17. 45
    0
      sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/EventCategory.java
  18. 1
    0
      sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java
  19. 2
    2
      sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequestTest.java

+ 3
- 1
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ProjectAnalysisModule.java View File

@@ -22,6 +22,7 @@ package org.sonar.server.projectanalysis;

import org.sonar.core.platform.Module;
import org.sonar.server.projectanalysis.ws.CreateEventAction;
import org.sonar.server.projectanalysis.ws.DeleteEventAction;
import org.sonar.server.projectanalysis.ws.ProjectAnalysesWs;

public class ProjectAnalysisModule extends Module {
@@ -31,7 +32,8 @@ public class ProjectAnalysisModule extends Module {
add(
ProjectAnalysesWs.class,
// actions
CreateEventAction.class);
CreateEventAction.class,
DeleteEventAction.class);
}

}

+ 5
- 5
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java View File

@@ -42,16 +42,16 @@ import org.sonar.server.user.UserSession;
import org.sonarqube.ws.ProjectAnalyses.CreateEventResponse;
import org.sonarqube.ws.ProjectAnalyses.Event;
import org.sonarqube.ws.client.projectanalysis.CreateEventRequest;
import org.sonarqube.ws.client.projectanalysis.CreateEventRequest.Category;
import org.sonarqube.ws.client.projectanalysis.EventCategory;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.lang.String.format;
import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.client.projectanalysis.CreateEventRequest.Category.OTHER;
import static org.sonarqube.ws.client.projectanalysis.CreateEventRequest.Category.VERSION;
import static org.sonarqube.ws.client.projectanalysis.CreateEventRequest.Category.fromLabel;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.OTHER;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.fromLabel;
import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_ANALYSIS;
import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_CATEGORY;
import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_DESCRIPTION;
@@ -149,7 +149,7 @@ public class CreateEventAction implements ProjectAnalysesWsAction {
return CreateEventRequest.builder()
.setAnalysis(request.mandatoryParam(PARAM_ANALYSIS))
.setName(request.mandatoryParam(PARAM_NAME))
.setCategory(request.mandatoryParamAsEnum(PARAM_CATEGORY, Category.class))
.setCategory(request.mandatoryParamAsEnum(PARAM_CATEGORY, EventCategory.class))
.setDescription(request.param(PARAM_DESCRIPTION))
.build();
}

+ 111
- 0
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/DeleteEventAction.java View File

@@ -0,0 +1,111 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program 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.
*
* This program 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.projectanalysis.ws;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
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.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.client.projectanalysis.DeleteEventRequest;

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.OTHER;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION;
import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_EVENT;

public class DeleteEventAction implements ProjectAnalysesWsAction {
private static final Set<String> AUTHORIZED_CATEGORIES = ImmutableSet.of(VERSION.getLabel(), OTHER.getLabel());
private static final String AUTHORIZED_CATEGORIES_INLINED = Joiner.on(", ").join(AUTHORIZED_CATEGORIES);

private final DbClient dbClient;
private final UserSession userSession;

public DeleteEventAction(DbClient dbClient, UserSession userSession) {
this.dbClient = dbClient;
this.userSession = userSession;
}

@Override
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("delete_event")
.setDescription("Delete an analysis event.<br>" +
"Requires one of the following permissions:" +
"<ul>" +
" <li>'Administer System'</li>" +
" <li>'Administer' rights on the specified project</li>" +
"</ul>")
.setPost(true)
.setSince("6.3")
.setHandler(this);

action.createParam(PARAM_EVENT)
.setDescription("Event key")
.setRequired(true);
}

@Override
public void handle(Request request, Response response) throws Exception {
DeleteEventRequest deleteEventRequest = toDeleteEventRequest(request);
doHandle(deleteEventRequest);
response.noContent();
}

private void doHandle(DeleteEventRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
EventDto dbEvent = dbClient.eventDao().selectByUuid(dbSession, request.getEvent())
.orElseThrow(() -> new NotFoundException(format("Event '%s' not found", request.getEvent())));
checkPermissions(dbEvent);
checkArgument(AUTHORIZED_CATEGORIES.contains(dbEvent.getCategory()), "Event of category '%s' cannot be deleted. Authorized categories: %s", dbEvent.getCategory(),
AUTHORIZED_CATEGORIES_INLINED);

deleteEvent(dbSession, dbEvent);
}
}

private void deleteEvent(DbSession dbSession, EventDto dbEvent) {
if (VERSION.getLabel().equals(dbEvent.getCategory())) {
SnapshotDto analysis = dbClient.snapshotDao().selectByUuid(dbSession, dbEvent.getAnalysisUuid())
.orElseThrow(() -> new IllegalStateException(format("Analysis '%s' not found", dbEvent.getAnalysisUuid())));
checkArgument(!analysis.getLast(), "Cannot delete the version event of last analysis");
dbClient.snapshotDao().updateVersion(dbSession, analysis.getUuid(), null);
}
dbClient.eventDao().delete(dbSession, dbEvent.getUuid());
dbSession.commit();
}

private void checkPermissions(EventDto event) {
userSession.checkComponentUuidPermission(UserRole.ADMIN, event.getComponentUuid());
}

private static DeleteEventRequest toDeleteEventRequest(Request httpRequest) {
return new DeleteEventRequest(httpRequest.mandatoryParam(PARAM_EVENT));
}
}

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ProjectAnalysisModuleTest.java View File

@@ -31,6 +31,6 @@ public class ProjectAnalysisModuleTest {
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new ProjectAnalysisModule().configure(container);
assertThat(container.size()).isEqualTo(2 + 2);
assertThat(container.size()).isEqualTo(2 + 3);
}
}

+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/CreateEventActionTest.java View File

@@ -60,8 +60,8 @@ import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.component.SnapshotTesting.newSnapshot;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.WsRequest.Method.POST;
import static org.sonarqube.ws.client.projectanalysis.CreateEventRequest.Category.OTHER;
import static org.sonarqube.ws.client.projectanalysis.CreateEventRequest.Category.VERSION;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.OTHER;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION;
import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_ANALYSIS;
import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_CATEGORY;
import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_DESCRIPTION;

+ 164
- 0
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/DeleteEventActionTest.java View File

@@ -0,0 +1,164 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program 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.
*
* This program 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.projectanalysis.ws;

import java.util.List;
import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;

import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.event.EventTesting.newEvent;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION;
import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_EVENT;

public class DeleteEventActionTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
public UserSessionRule userSession = UserSessionRule.standalone().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();

private WsActionTester ws = new WsActionTester(new DeleteEventAction(db.getDbClient(), userSession));

@Test
public void delete_event() {
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto());
db.events().insertEvent(newEvent(analysis).setUuid("E1"));
db.events().insertEvent(newEvent(analysis).setUuid("E2"));

call("E2");

List<EventDto> events = db.getDbClient().eventDao().selectByAnalysisUuid(db.getSession(), analysis.getUuid());
assertThat(events).extracting(EventDto::getUuid).containsExactly("E1");
}

@Test
public void delete_version_event() {
ComponentDto project = db.components().insertProject();
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setVersion("5.6.3").setLast(false));
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel()));

call("E1");

SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get();
assertThat(newAnalysis.getVersion()).isNull();
}

@Test
public void delete_event_as_project_admin() {
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto("P1"));
db.events().insertEvent(newEvent(analysis).setUuid("E1"));
userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, "P1");

call("E1");

assertThat(db.countRowsOfTable("events")).isEqualTo(0);
}

@Test
public void fail_if_version_for_last_analysis() {
ComponentDto project = db.components().insertProject();
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setVersion("5.6.3").setLast(true));
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel()));

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Cannot delete the version event of last analysis");

call("E1");
}

@Test
public void fail_if_category_different_than_other_and_version() {
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto("P1"));
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory("Profile"));

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Event of category 'Profile' cannot be deleted. Authorized categories: Version, Other");

call("E1");
}

@Test
public void fail_if_event_does_not_exist() {
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("E42' not found");

call("E42");
}

@Test
public void fail_if_not_enough_permission() {
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto());
db.events().insertEvent(newEvent(analysis).setUuid("E1"));
userSession.anonymous();

expectedException.expect(ForbiddenException.class);

call("E1");
}

@Test
public void fail_if_event_not_provided() {
expectedException.expect(IllegalArgumentException.class);

call(null);
}

@Test
public void ws_definition() {
WebService.Action definition = ws.getDef();
assertThat(definition.key()).isEqualTo("delete_event");
assertThat(definition.isPost()).isTrue();
assertThat(definition.isInternal()).isFalse();
assertThat(definition.param(PARAM_EVENT).isRequired()).isTrue();
}

private void call(@Nullable String event) {
TestRequest request = ws.newRequest();
if (event != null) {
request.setParam(PARAM_EVENT, event);
}

request.execute();
}
}

+ 1
- 1
sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java View File

@@ -138,7 +138,7 @@ public class SnapshotDao implements Dao {
insert(session, Lists.asList(item, others));
}

public void updateVersion(DbSession dbSession, String analysisUuid, String version) {
public void updateVersion(DbSession dbSession, String analysisUuid, @Nullable String version) {
mapper(dbSession).updateVersion(analysisUuid, version);
}


+ 2
- 1
sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java View File

@@ -22,6 +22,7 @@ package org.sonar.db.component;
import java.util.Collection;
import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;

@@ -56,5 +57,5 @@ public interface SnapshotMapper {

void setIsLastFlagForAnalysisUuid(@Param("analysisUuid") String analysisUuid);

void updateVersion(@Param("analysisUuid") String analysisUuid, @Param("version") String version);
void updateVersion(@Param("analysisUuid") String analysisUuid, @Param("version") @Nullable String version);
}

+ 10
- 1
sonar-db/src/main/java/org/sonar/db/event/EventDao.java View File

@@ -20,11 +20,16 @@
package org.sonar.db.event;

import java.util.List;
import java.util.Optional;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;

public class EventDao implements Dao {

public Optional<EventDto> selectByUuid(DbSession dbSession, String uuid) {
return Optional.ofNullable(mapper(dbSession).selectByUuid(uuid));
}

public List<EventDto> selectByComponentUuid(DbSession session, String componentUuid) {
return session.getMapper(EventMapper.class).selectByComponentUuid(componentUuid);
}
@@ -40,7 +45,11 @@ public class EventDao implements Dao {
}

public void delete(DbSession session, Long id) {
session.getMapper(EventMapper.class).delete(id);
mapper(session).deleteById(id);
}

public void delete(DbSession session, String uuid) {
mapper(session).deleteByUuid(uuid);
}

private static EventMapper mapper(DbSession session) {

+ 5
- 1
sonar-db/src/main/java/org/sonar/db/event/EventMapper.java View File

@@ -23,11 +23,15 @@ import java.util.List;

public interface EventMapper {

EventDto selectByUuid(String uuid);

List<EventDto> selectByComponentUuid(String componentUuid);

List<EventDto> selectByAnalysisUuid(String analysisUuid);

void insert(EventDto dto);

void delete(long id);
void deleteById(long id);

void deleteByUuid(String uuid);
}

+ 14
- 1
sonar-db/src/main/resources/org/sonar/db/event/EventMapper.xml View File

@@ -15,6 +15,15 @@
e.created_at as "createdAt"
</sql>

<select id="selectByUuid" parameterType="String" resultType="Event">
SELECT
<include refid="eventColumns"/>
FROM events e
<where>
AND e.uuid=#{uuid}
</where>
</select>

<select id="selectByComponentUuid" parameterType="String" resultType="Event">
SELECT
<include refid="eventColumns"/>
@@ -47,9 +56,13 @@
#{createdAt, jdbcType=BIGINT})
</insert>

<delete id="delete">
<delete id="deleteById" parameterType="Long">
DELETE FROM events WHERE id=#{id}
</delete>

<delete id="deleteByUuid" parameterType="String">
DELETE FROM events WHERE uuid=#{uuid}
</delete>

</mapper>


+ 0
- 1
sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java View File

@@ -305,7 +305,6 @@ public class SnapshotDaoTest {
underTest.updateVersion(dbSession, "A1", "5.6.3");

SnapshotDto result = underTest.selectByUuid(dbSession, "A1").get();

assertThat(result.getVersion()).isEqualTo("5.6.3");
}


+ 25
- 1
sonar-db/src/test/java/org/sonar/db/event/EventDaoTest.java View File

@@ -20,6 +20,7 @@
package org.sonar.db.event;

import java.util.List;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -46,6 +47,19 @@ public class EventDaoTest {

EventDao underTest = dbTester.getDbClient().eventDao();

@Test
public void select_by_uuid() {
SnapshotDto analysis = newAnalysis(newProjectDto());
dbTester.events().insertEvent(newEvent(analysis).setUuid("A1"));
dbTester.events().insertEvent(newEvent(analysis).setUuid("A2"));
dbTester.events().insertEvent(newEvent(analysis).setUuid("A3"));

Optional<EventDto> result = underTest.selectByUuid(dbSession, "A2");

assertThat(result).isPresent();
assertThat(result.get().getUuid()).isEqualTo("A2");
}

@Test
public void select_by_component_uuid() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
@@ -116,7 +130,7 @@ public class EventDaoTest {
}

@Test
public void delete() {
public void delete_by_id() {
dbTester.prepareDbUnit(getClass(), "delete.xml");

underTest.delete(dbTester.getSession(), 1L);
@@ -125,4 +139,14 @@ public class EventDaoTest {
assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0);
}

@Test
public void delete_by_uuid() {
dbTester.events().insertEvent(newEvent(newAnalysis(newProjectDto())).setUuid("E1"));

underTest.delete(dbTester.getSession(), "E1");
dbTester.commit();

assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0);
}

}

+ 1
- 1
sonar-db/src/test/java/org/sonar/db/event/EventTesting.java View File

@@ -37,7 +37,7 @@ public class EventTesting {
.setUuid(randomAlphanumeric(40))
.setName(randomAlphanumeric(400))
.setDescription(randomAlphanumeric(400))
.setCategory(randomAlphanumeric(50))
.setCategory("Other")
.setComponentUuid(analysis.getComponentUuid())
.setCreatedAt(System.currentTimeMillis())
.setDate(System.currentTimeMillis());

+ 4
- 27
sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequest.java View File

@@ -27,7 +27,7 @@ import static com.google.common.base.Preconditions.checkArgument;

public class CreateEventRequest {
private final String analysis;
private final Category category;
private final EventCategory category;
private final String name;
private final String description;

@@ -42,7 +42,7 @@ public class CreateEventRequest {
return analysis;
}

public Category getCategory() {
public EventCategory getCategory() {
return category;
}

@@ -61,7 +61,7 @@ public class CreateEventRequest {

public static class Builder {
private String analysis;
private Category category = Category.OTHER;
private EventCategory category = EventCategory.OTHER;
private String name;
private String description;

@@ -74,7 +74,7 @@ public class CreateEventRequest {
return this;
}

public Builder setCategory(Category category) {
public Builder setCategory(EventCategory category) {
this.category = category;
return this;
}
@@ -98,27 +98,4 @@ public class CreateEventRequest {
}
}

public enum Category {
VERSION("Version"), OTHER("Other");

private final String label;

Category(String label) {
this.label = label;
}

public String getLabel() {
return label;
}

public static Category fromLabel(String label) {
for (Category category : values()) {
if (category.getLabel().equals(label)) {
return category;
}
}

throw new IllegalArgumentException("Unknown event category label '" + label + "'");
}
}
}

+ 35
- 0
sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/DeleteEventRequest.java View File

@@ -0,0 +1,35 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program 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.
*
* This program 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.sonarqube.ws.client.projectanalysis;

import static java.util.Objects.requireNonNull;

public class DeleteEventRequest {
private final String event;

public DeleteEventRequest(String event) {
this.event = requireNonNull(event);
}

public String getEvent() {
return event;
}
}

+ 45
- 0
sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/EventCategory.java View File

@@ -0,0 +1,45 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program 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.
*
* This program 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.sonarqube.ws.client.projectanalysis;

public enum EventCategory {
VERSION("Version"), OTHER("Other");

private final String label;

EventCategory(String label) {
this.label = label;
}

public String getLabel() {
return label;
}

public static EventCategory fromLabel(String label) {
for (EventCategory category : values()) {
if (category.getLabel().equals(label)) {
return category;
}
}

throw new IllegalArgumentException("Unknown event category label '" + label + "'");
}
}

+ 1
- 0
sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java View File

@@ -25,6 +25,7 @@ public class ProjectAnalysesWsParameters {
public static final String PARAM_CATEGORY = "category";
public static final String PARAM_NAME = "name";
public static final String PARAM_DESCRIPTION = "description";
public static final String PARAM_EVENT = "event";

private ProjectAnalysesWsParameters() {
// static access only

+ 2
- 2
sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequestTest.java View File

@@ -25,8 +25,8 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.sonarqube.ws.client.projectanalysis.CreateEventRequest.Category.OTHER;
import static org.sonarqube.ws.client.projectanalysis.CreateEventRequest.Category.VERSION;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.OTHER;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION;

public class CreateEventRequestTest {


Loading…
Cancel
Save