forked from camunda/camunda-bpm-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine-rest): add event subscription endpoint
Related to CAM-11792 Closes PR camunda#790
- Loading branch information
1 parent
5347d60
commit 9c145c5
Showing
8 changed files
with
709 additions
and
3 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...t/engine-rest/src/main/java/org/camunda/bpm/engine/rest/EventSubscriptionRestService.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,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); | ||
|
||
} |
196 changes: 196 additions & 0 deletions
196
...rest/src/main/java/org/camunda/bpm/engine/rest/dto/runtime/EventSubscriptionQueryDto.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,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(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.