Skip to content

Commit

Permalink
feat(engine-rest): add event subscription endpoint
Browse files Browse the repository at this point in the history
Related to CAM-11792
Closes PR camunda#790
  • Loading branch information
garima-camunda authored and yanavasileva committed May 5, 2020
1 parent 5347d60 commit 9c145c5
Show file tree
Hide file tree
Showing 8 changed files with 709 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.engine.rest;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

import org.camunda.bpm.engine.rest.dto.CountResultDto;
import org.camunda.bpm.engine.rest.dto.runtime.EventSubscriptionDto;
import org.camunda.bpm.engine.runtime.EventSubscriptionQuery;

@Produces(MediaType.APPLICATION_JSON)
public interface EventSubscriptionRestService {

public static final String PATH = "/event-subscription";

/**
* Exposes the {@link EventSubscriptionQuery} interface as a REST service.
*
* @param uriInfo
* @param firstResult
* @param maxResults
* @return
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
List<EventSubscriptionDto> getEventSubscriptions(@Context UriInfo uriInfo,
@QueryParam("firstResult") Integer firstResult,
@QueryParam("maxResults") Integer maxResults);

/**
* Number of event subscriptions
*
* @return
*/
@GET
@Path("/count")
@Produces(MediaType.APPLICATION_JSON)
CountResultDto getEventSubscriptionsCount(@Context UriInfo uriInfo);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.engine.rest.dto.runtime;

import static java.lang.Boolean.TRUE;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.ws.rs.core.MultivaluedMap;

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.rest.dto.AbstractQueryDto;
import org.camunda.bpm.engine.rest.dto.CamundaQueryParam;
import org.camunda.bpm.engine.rest.dto.converter.BooleanConverter;
import org.camunda.bpm.engine.rest.dto.converter.StringListConverter;
import org.camunda.bpm.engine.runtime.EventSubscriptionQuery;

import com.fasterxml.jackson.databind.ObjectMapper;

public class EventSubscriptionQueryDto extends AbstractQueryDto<EventSubscriptionQuery> {

private static final String SORT_BY_TENANT_ID = "tenantId";
private static final String SORT_BY_CREATED = "created";

private static final List<String> VALID_SORT_BY_VALUES;
static {
VALID_SORT_BY_VALUES = new ArrayList<String>();
VALID_SORT_BY_VALUES.add(SORT_BY_TENANT_ID);
VALID_SORT_BY_VALUES.add(SORT_BY_CREATED);
}

private String eventSubscriptionId;
private String eventName;
private String eventType;
private String executionId;
private String processInstanceId;
private String activityId;
private List<String> tenantIdIn;
private Boolean withoutTenantId;
private Boolean includeEventSubscriptionsWithoutTenantId;

public EventSubscriptionQueryDto() {

}

public EventSubscriptionQueryDto(ObjectMapper objectMapper, MultivaluedMap<String, String> queryParameters) {
super(objectMapper, queryParameters);
}

public String getEventSubscriptionId() {
return eventSubscriptionId;
}

@CamundaQueryParam("eventSubscriptionId")
public void setEventSubscriptionId(String eventSubscriptionId) {
this.eventSubscriptionId = eventSubscriptionId;
}

public String getEventName() {
return eventName;
}

@CamundaQueryParam("eventName")
public void setEventName(String eventName) {
this.eventName = eventName;
}

public String getEventType() {
return eventType;
}

@CamundaQueryParam("eventType")
public void setEventType(String eventType) {
this.eventType = eventType;
}

public String getExecutionId() {
return executionId;
}

@CamundaQueryParam("executionId")
public void setExecutionId(String executionId) {
this.executionId = executionId;
}

public String getProcessInstanceId() {
return processInstanceId;
}

@CamundaQueryParam("processInstanceId")
public void setProcessInstanceId(String processInstanceId) {
this.processInstanceId = processInstanceId;
}

public String getActivityId() {
return activityId;
}

@CamundaQueryParam("activityId")
public void setActivityId(String activityId) {
this.activityId = activityId;
}

public List<String> getTenantIdIn() {
return tenantIdIn;
}

@CamundaQueryParam(value = "tenantIdIn", converter = StringListConverter.class)
public void setTenantIdIn(List<String> tenantIdIn) {
this.tenantIdIn = tenantIdIn;
}

public Boolean getWithoutTenantId() {
return withoutTenantId;
}

@CamundaQueryParam(value = "withoutTenantId", converter = BooleanConverter.class)
public void setWithoutTenantId(Boolean withoutTenantId) {
this.withoutTenantId = withoutTenantId;
}

public Boolean getIncludeEventSubscriptionsWithoutTenantId() {
return includeEventSubscriptionsWithoutTenantId;
}

@CamundaQueryParam(value = "includeEventSubscriptionsWithoutTenantId", converter = BooleanConverter.class)
public void setIncludeEventSubscriptionsWithoutTenantId(Boolean includeEventSubscriptionsWithoutTenantId) {
this.includeEventSubscriptionsWithoutTenantId = includeEventSubscriptionsWithoutTenantId;
}

@Override
protected boolean isValidSortByValue(String value) {
return VALID_SORT_BY_VALUES.contains(value);
}

@Override
protected EventSubscriptionQuery createNewQuery(ProcessEngine engine) {
return engine.getRuntimeService().createEventSubscriptionQuery();
}

@Override
protected void applyFilters(EventSubscriptionQuery query) {
if (eventSubscriptionId != null) {
query.eventSubscriptionId(eventSubscriptionId);
}
if (eventName != null) {
query.eventName(eventName);
}
if (eventType != null) {
query.eventType(eventType);
}
if (executionId != null) {
query.executionId(executionId);
}
if (processInstanceId != null) {
query.processInstanceId(processInstanceId);
}
if (activityId != null) {
query.activityId(activityId);
}
if (tenantIdIn != null && !tenantIdIn.isEmpty()) {
query.tenantIdIn(tenantIdIn.toArray(new String[tenantIdIn.size()]));
}
if (TRUE.equals(withoutTenantId)) {
query.withoutTenantId();
}
if (TRUE.equals(includeEventSubscriptionsWithoutTenantId)) {
query.includeEventSubscriptionsWithoutTenantId();
}
}

@Override
protected void applySortBy(EventSubscriptionQuery query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) {
if (sortBy.equals(SORT_BY_CREATED)) {
query.orderByCreated();
} else if (sortBy.equals(SORT_BY_TENANT_ID)) {
query.orderByTenantId();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.camunda.bpm.engine.rest.DecisionDefinitionRestService;
import org.camunda.bpm.engine.rest.DecisionRequirementsDefinitionRestService;
import org.camunda.bpm.engine.rest.DeploymentRestService;
import org.camunda.bpm.engine.rest.EventSubscriptionRestService;
import org.camunda.bpm.engine.rest.ExecutionRestService;
import org.camunda.bpm.engine.rest.ExternalTaskRestService;
import org.camunda.bpm.engine.rest.FilterRestService;
Expand Down Expand Up @@ -298,6 +299,13 @@ public SchemaLogRestService getSchemaLogRestService(String engineName) {
return subResource;
}

public EventSubscriptionRestService getEventSubscriptionRestService(String engineName) {
String rootResourcePath = getRelativeEngineUri(engineName).toASCIIString();
EventSubscriptionRestServiceImpl subResource = new EventSubscriptionRestServiceImpl(engineName, getObjectMapper());
subResource.setRelativeRootResourceUri(rootResourcePath);
return subResource;
}

protected abstract URI getRelativeEngineUri(String engineName);

protected ObjectMapper getObjectMapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.camunda.bpm.engine.rest.DecisionDefinitionRestService;
import org.camunda.bpm.engine.rest.DecisionRequirementsDefinitionRestService;
import org.camunda.bpm.engine.rest.DeploymentRestService;
import org.camunda.bpm.engine.rest.EventSubscriptionRestService;
import org.camunda.bpm.engine.rest.ExecutionRestService;
import org.camunda.bpm.engine.rest.ExternalTaskRestService;
import org.camunda.bpm.engine.rest.FilterRestService;
Expand Down Expand Up @@ -182,7 +183,6 @@ public ModificationRestService getModificationRestService() {
return super.getModificationRestService(null);
}


@Path(BatchRestService.PATH)
public BatchRestService getBatchRestService() {
return super.getBatchRestService(null);
Expand Down Expand Up @@ -218,6 +218,11 @@ public SchemaLogRestService getSchemaLogRestService() {
return super.getSchemaLogRestService(null);
}

@Path(EventSubscriptionRestService.PATH)
public EventSubscriptionRestService getEventSubscriptionRestService() {
return super.getEventSubscriptionRestService(null);
}

@Override
protected URI getRelativeEngineUri(String engineName) {
// the default engine
Expand Down
Loading

0 comments on commit 9c145c5

Please sign in to comment.