http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/OAuthToken.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/OAuthToken.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/OAuthToken.java index 11c3842..880cf7f 100644 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/OAuthToken.java +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/OAuthToken.java @@ -30,14 +30,12 @@ import org.slf4j.LoggerFactory; public class OAuthToken { private static final Logger LOGGER = LoggerFactory.getLogger(OAuthToken.class); - private final String url; private final ServiceNowConfiguration configuration; private ClientAccessToken token; private String authString; private long expireAt; - public OAuthToken(String url, ServiceNowConfiguration configuration) { - this.url = url; + public OAuthToken(ServiceNowConfiguration configuration) { this.configuration = configuration; this.token = null; this.authString = null; @@ -49,7 +47,7 @@ public class OAuthToken { LOGGER.debug("Generate OAuth token"); token = OAuthClientUtils.getAccessToken( - WebClient.create(url), + WebClient.create(configuration.getOauthTokenUrl()), new Consumer( configuration.getOauthClientId(), configuration.getOauthClientSecret()), @@ -74,7 +72,7 @@ public class OAuthToken { LOGGER.debug("OAuth token is expired, refresh it"); token = OAuthClientUtils.refreshAccessToken( - WebClient.create(url), + WebClient.create(configuration.getOauthTokenUrl()), new Consumer( configuration.getOauthClientId(), configuration.getOauthClientSecret()),
http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregate.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregate.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregate.java deleted file mode 100644 index b723387..0000000 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregate.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); 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.apache.camel.component.servicenow.model; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; - -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.camel.component.servicenow.ServiceNowException; - -@Path("/stats") -@Produces("application/json") -@Consumes("application/json") -public interface ServiceNowAggregate { - - @GET - @Path("{tableName}") - JsonNode retrieveStats( - @PathParam("tableName") String tableName, - @QueryParam("sysparm_query") String query, - @QueryParam("sysparm_avg_fields") String avgFields, - @QueryParam("sysparm_count") String count, - @QueryParam("sysparm_min_fields") String minFields, - @QueryParam("sysparm_max_fields") String maxFields, - @QueryParam("sysparm_sum_fields") String sumFields, - @QueryParam("sysparm_group_by") String groupBy, - @QueryParam("sysparm_order_by") String orderBy, - @QueryParam("sysparm_having") String having, - @QueryParam("sysparm_display_value") String displayValue - ) throws ServiceNowException; -} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregateProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregateProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregateProcessor.java deleted file mode 100644 index 964b772..0000000 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregateProcessor.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); 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.apache.camel.component.servicenow.model; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.component.servicenow.ServiceNowConstants; -import org.apache.camel.component.servicenow.ServiceNowEndpoint; -import org.apache.camel.component.servicenow.ServiceNowProducerProcessor; -import org.apache.camel.util.ObjectHelper; - -public class ServiceNowAggregateProcessor extends ServiceNowProducerProcessor<ServiceNowAggregate> { - - public static final ServiceNowProducerProcessor.Supplier SUPPLIER = new ServiceNowProducerProcessor.Supplier() { - @Override - public Processor get(ServiceNowEndpoint endpoint) throws Exception { - return new ServiceNowAggregateProcessor(endpoint); - } - }; - - public ServiceNowAggregateProcessor(ServiceNowEndpoint endpoint) throws Exception { - super(endpoint, ServiceNowAggregate.class); - } - - @Override - protected void doProcess(Exchange exchange, Class<?> model, String action, String tableName, String sysId) throws Exception { - if (ObjectHelper.equal(ServiceNowConstants.ACTION_RETRIEVE, action, true)) { - retrieveStats(exchange.getIn(), model, tableName); - } else { - throw new IllegalArgumentException("Unknown action " + action); - } - } - - private void retrieveStats(Message in, Class<?> model, String tableName) throws Exception { - setBody( - in, - model, - client.retrieveStats( - tableName, - in.getHeader(ServiceNowConstants.SYSPARM_QUERY, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_AVG_FIELDS, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_COUNT, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_MIN_FIELDS, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_MAX_FIELDS, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_SUM_FIELDS, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_GROUP_BY, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_ORDER_BY, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_HAVING, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class) - ) - ); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSet.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSet.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSet.java deleted file mode 100644 index 865187e..0000000 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSet.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); 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.apache.camel.component.servicenow.model; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.camel.component.servicenow.ServiceNowException; - -@Path("/import") -@Produces("application/json") -@Consumes("application/json") -public interface ServiceNowImportSet { - - @GET - @Path("{tableName}/{sysId}") - JsonNode retrieveRecordById( - @PathParam("tableName") String tableName, - @PathParam("sysId") String id - ) throws ServiceNowException; - - @POST - @Path("{tableName}") - JsonNode createRecord( - @PathParam("tableName") String tableName, - String body - ) throws ServiceNowException; -} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSetProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSetProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSetProcessor.java deleted file mode 100644 index e76e9c1..0000000 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSetProcessor.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); 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.apache.camel.component.servicenow.model; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.component.servicenow.ServiceNowConstants; -import org.apache.camel.component.servicenow.ServiceNowEndpoint; -import org.apache.camel.component.servicenow.ServiceNowProducerProcessor; -import org.apache.camel.util.ObjectHelper; - -public class ServiceNowImportSetProcessor extends ServiceNowProducerProcessor<ServiceNowImportSet> { - - public static final ServiceNowProducerProcessor.Supplier SUPPLIER = new ServiceNowProducerProcessor.Supplier() { - @Override - public Processor get(ServiceNowEndpoint endpoint) throws Exception { - return new ServiceNowImportSetProcessor(endpoint); - } - }; - - public ServiceNowImportSetProcessor(ServiceNowEndpoint endpoint) throws Exception { - super(endpoint, ServiceNowImportSet.class); - } - - @Override - protected void doProcess(Exchange exchange, Class<?> model, String action, String tableName, String sysId) throws Exception { - if (ObjectHelper.equal(ServiceNowConstants.ACTION_RETRIEVE, action, true)) { - retrieveRecord(exchange.getIn(), model, tableName, sysId); - } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_CREATE, action, true)) { - createRecord(exchange.getIn(), model, tableName); - } else { - throw new IllegalArgumentException("Unknown action " + action); - } - } - - /* - * GET https://instance.service-now.com/api/now/import/{tableName}/{sys_id} - */ - private void retrieveRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception { - setBody( - in, - model, - client.retrieveRecordById( - tableName, - ObjectHelper.notNull(sysId, "sysId")) - ); - } - - - /* - * POST https://instance.service-now.com/api/now/import/{tableName} - */ - private void createRecord(Message in, Class<?> model, String tableName) throws Exception { - validateBody(in, model); - setBody( - in, - model, - client.createRecord( - tableName, - mapper.writeValueAsString(in.getBody()) - ) - ); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTable.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTable.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTable.java deleted file mode 100644 index 366d8ee..0000000 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTable.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); 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.apache.camel.component.servicenow.model; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; - -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.camel.component.servicenow.ServiceNowException; -import org.apache.cxf.jaxrs.ext.PATCH; - -@Path("/table") -@Produces("application/json") -@Consumes("application/json") -public interface ServiceNowTable { - - @GET - @Path("{tableName}") - JsonNode retrieveRecord( - @PathParam("tableName") String tableName, - @QueryParam("sysparm_query") String query, - @QueryParam("sysparm_display_value") String displayValue, - @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink, - @QueryParam("sysparm_fields") String fields, - @QueryParam("sysparm_limit") Integer limit, - @QueryParam("sysparm_view") String view - ) throws ServiceNowException; - - @GET - @Path("{tableName}/{sysId}") - JsonNode retrieveRecordById( - @PathParam("tableName") String tableName, - @PathParam("sysId") String id, - @QueryParam("sysparm_display_value") String displayValue, - @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink, - @QueryParam("sysparm_fields") String fields, - @QueryParam("sysparm_view") String view - ) throws ServiceNowException; - - @POST - @Path("{tableName}") - JsonNode createRecord( - @PathParam("tableName") String tableName, - @QueryParam("sysparm_display_value") String displayValue, - @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink, - @QueryParam("sysparm_fields") String fields, - @QueryParam("sysparm_input_display_value") Boolean inputDisplayValue, - @QueryParam("sysparm_suppress_auto_sys_field") Boolean suppressAutoSysField, - @QueryParam("sysparm_view") String view, - String body - ) throws ServiceNowException; - - @PUT - @Path("{tableName}/{sysId}") - JsonNode modifyRecord( - @PathParam("tableName") String tableName, - @PathParam("sysId") String id, - @QueryParam("sysparm_display_value") String displayValue, - @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink, - @QueryParam("sysparm_fields") String fields, - @QueryParam("sysparm_input_display_value") Boolean inputDisplayValue, - @QueryParam("sysparm_suppress_auto_sys_field") Boolean suppressAutoSysField, - @QueryParam("sysparm_view") String view, - String body - ) throws ServiceNowException; - - @DELETE - @Path("{tableName}/{sysId}") - JsonNode deleteRecord( - @PathParam("tableName") String tableName, - @PathParam("sysId") String id - ) throws ServiceNowException; - - @PATCH - @Path("{tableName}/{sysId}") - JsonNode updateRecord( - @PathParam("tableName") String tableName, - @PathParam("sysId") String id, - @QueryParam("sysparm_display_value") String displayValue, - @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink, - @QueryParam("sysparm_fields") String fields, - @QueryParam("sysparm_input_display_value") Boolean inputDisplayValue, - @QueryParam("sysparm_suppress_auto_sys_field") Boolean suppressAutoSysField, - @QueryParam("sysparm_view") String view, - String body - ) throws ServiceNowException; -} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTableProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTableProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTableProcessor.java deleted file mode 100644 index 7b6504d..0000000 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTableProcessor.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); 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.apache.camel.component.servicenow.model; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.component.servicenow.ServiceNowConstants; -import org.apache.camel.component.servicenow.ServiceNowEndpoint; -import org.apache.camel.component.servicenow.ServiceNowProducerProcessor; -import org.apache.camel.util.ObjectHelper; - -public class ServiceNowTableProcessor extends ServiceNowProducerProcessor<ServiceNowTable> { - - public static final ServiceNowProducerProcessor.Supplier SUPPLIER = new ServiceNowProducerProcessor.Supplier() { - @Override - public Processor get(ServiceNowEndpoint endpoint) throws Exception { - return new ServiceNowTableProcessor(endpoint); - } - }; - - public ServiceNowTableProcessor(ServiceNowEndpoint endpoint) throws Exception { - super(endpoint, ServiceNowTable.class); - } - - @Override - protected void doProcess(Exchange exchange, Class<?> model, String action, String tableName, String sysId) throws Exception { - if (ObjectHelper.equal(ServiceNowConstants.ACTION_RETRIEVE, action, true)) { - retrieveRecord(exchange.getIn(), model, tableName, sysId); - } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_CREATE, action, true)) { - createRecord(exchange.getIn(), model, tableName); - } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_MODIFY, action, true)) { - modifyRecord(exchange.getIn(), model, tableName, sysId); - } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_DELETE, action, true)) { - deleteRecord(exchange.getIn(), model, tableName, sysId); - } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_UPDATE, action, true)) { - updateRecord(exchange.getIn(), model, tableName, sysId); - } else { - throw new IllegalArgumentException("Unknown action " + action); - } - } - - /* - * GET https://instance.service-now.com/api/now/table/{tableName} - * GET https://instance.service-now.com/api/now/table/{tableName}/{sys_id} - */ - private void retrieveRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception { - if (sysId == null) { - setBody( - in, - model, - client.retrieveRecord( - tableName, - in.getHeader(ServiceNowConstants.SYSPARM_QUERY, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class), - in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_LIMIT, Integer.class), - in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class) - ) - ); - } else { - setBody( - in, - model, - client.retrieveRecordById( - tableName, - ObjectHelper.notNull(sysId, "sysId"), - in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class), - in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class) - ) - ); - } - } - - /* - * POST https://instance.service-now.com/api/now/table/{tableName} - */ - private void createRecord(Message in, Class<?> model, String tableName) throws Exception { - validateBody(in, model); - setBody( - in, - model, - client.createRecord( - tableName, - in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class), - in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_INPUT_DISPLAY_VALUE, config.getInputDisplayValue(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, config.getSuppressAutoSysField(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class), - mapper.writeValueAsString(in.getBody()) - ) - ); - } - - /* - * PUT https://instance.service-now.com/api/now/table/{tableName}/{sys_id} - */ - private void modifyRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception { - validateBody(in, model); - setBody( - in, - model, - client.modifyRecord( - tableName, - ObjectHelper.notNull(sysId, "sysId"), - in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class), - in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_INPUT_DISPLAY_VALUE, config.getInputDisplayValue(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, config.getSuppressAutoSysField(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class), - mapper.writeValueAsString(in.getBody()) - ) - ); - } - - /* - * DELETE https://instance.service-now.com/api/now/table/{tableName}/{sys_id} - */ - private void deleteRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception { - setBody( - in, - model, - client.deleteRecord( - tableName, - ObjectHelper.notNull(sysId, "sysId")) - ); - } - - /* - * PATCH instance://dev21005.service-now.com/api/now/table/{tableName}/{sys_id} - */ - private void updateRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception { - validateBody(in, model); - setBody( - in, - model, - client.updateRecord( - tableName, - ObjectHelper.notNull(sysId, "sysId"), - in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class), - in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class), - in.getHeader(ServiceNowConstants.SYSPARM_INPUT_DISPLAY_VALUE, config.getInputDisplayValue(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, config.getSuppressAutoSysField(), Boolean.class), - in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class), - mapper.writeValueAsString(in.getBody()) - ) - ); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowAggregateProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowAggregateProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowAggregateProcessor.java new file mode 100644 index 0000000..925b16e --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowAggregateProcessor.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.fuji; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.ServiceNowConstants; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; +import org.apache.camel.util.ObjectHelper; + +class FujiServiceNowAggregateProcessor extends FujiServiceNowProcessor { + + FujiServiceNowAggregateProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + } + + @Override + protected void doProcess(Exchange exchange, Class<?> model, String action, String tableName, String sysId) throws Exception { + Response response; + if (ObjectHelper.equal(ServiceNowConstants.ACTION_RETRIEVE, action, true)) { + response = retrieveStats(exchange.getIn(), tableName); + } else { + throw new IllegalArgumentException("Unknown action " + action); + } + + setBodyAndHeaders(exchange.getIn(), model, response); + } + + private Response retrieveStats(Message in, String tableName) throws Exception { + return client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("stats") + .path(tableName) + .query(ServiceNowParams.SYSPARM_QUERY, in) + .query(ServiceNowParams.SYSPARM_AVG_FIELDS, in) + .query(ServiceNowParams.SYSPARM_COUNT, in) + .query(ServiceNowParams.SYSPARM_MIN_FIELDS, in) + .query(ServiceNowParams.SYSPARM_QUERY, in) + .query(ServiceNowParams.SYSPARM_MAX_FIELDS, in) + .query(ServiceNowParams.SYSPARM_SUM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_GROUP_BY, in) + .query(ServiceNowParams.SYSPARM_ORDER_BY, in) + .query(ServiceNowParams.SYSPARM_HAVING, in) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .invoke(HttpMethod.GET); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowImportSetProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowImportSetProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowImportSetProcessor.java new file mode 100644 index 0000000..e118bd0 --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowImportSetProcessor.java @@ -0,0 +1,77 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.fuji; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.ServiceNowConstants; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.util.ObjectHelper; + +class FujiServiceNowImportSetProcessor extends FujiServiceNowProcessor { + + FujiServiceNowImportSetProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + } + + @Override + protected void doProcess(Exchange exchange, Class<?> model, String action, String tableName, String sysId) throws Exception { + Response response; + if (ObjectHelper.equal(ServiceNowConstants.ACTION_RETRIEVE, action, true)) { + response = retrieveRecord(exchange.getIn(), tableName, sysId); + } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_CREATE, action, true)) { + response = createRecord(exchange.getIn(), model, tableName); + } else { + throw new IllegalArgumentException("Unknown action " + action); + } + + setBodyAndHeaders(exchange.getIn(), model, response); + } + + /* + * GET + * https://instance.service-now.com/api/now/import/{tableName}/{sys_id} + */ + private Response retrieveRecord(Message in, String tableName, String sysId) throws Exception { + return client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("import") + .path(tableName) + .path(ObjectHelper.notNull(sysId, "sysId")) + .invoke(HttpMethod.GET); + } + + /* + * POST + * https://instance.service-now.com/api/now/import/{tableName} + */ + private Response createRecord(Message in, Class<?> model, String tableName) throws Exception { + validateBody(in, model); + return client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("import") + .path(tableName) + .invoke(HttpMethod.POST, in.getMandatoryBody()); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowProcessor.java new file mode 100644 index 0000000..bfde592 --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowProcessor.java @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.fuji; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowConstants; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; +import org.apache.camel.util.ObjectHelper; + +public abstract class FujiServiceNowProcessor extends AbstractServiceNowProcessor { + protected FujiServiceNowProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + } + + @Override + public void process(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + final String action = in.getHeader(ServiceNowConstants.ACTION, String.class); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + doProcess( + exchange, + ObjectHelper.notNull(model, "model"), + ObjectHelper.notNull(action, "action"), + ObjectHelper.notNull(tableName, "tableName"), + sysId); + } + + protected abstract void doProcess( + Exchange exchange, + Class<?> model, + String action, + String tableName, + String sysId) throws Exception; +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowProducer.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowProducer.java new file mode 100644 index 0000000..3d2f6cc --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowProducer.java @@ -0,0 +1,36 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.fuji; + +import org.apache.camel.component.servicenow.AbstractServiceNowProducer; +import org.apache.camel.component.servicenow.ServiceNowConstants; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowRelease; + +/** + * The Fuji ServiceNow producer. + */ +public class FujiServiceNowProducer extends AbstractServiceNowProducer { + public FujiServiceNowProducer(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint, ServiceNowRelease.FUJI); + + bind(ServiceNowConstants.RESOURCE_TABLE, new FujiServiceNowTableProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_AGGREGATE, new FujiServiceNowAggregateProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_IMPORT, new FujiServiceNowImportSetProcessor(endpoint)); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowTableProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowTableProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowTableProcessor.java new file mode 100644 index 0000000..4cd25be --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/fuji/FujiServiceNowTableProcessor.java @@ -0,0 +1,163 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.fuji; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.ServiceNowConstants; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; +import org.apache.camel.util.ObjectHelper; + +class FujiServiceNowTableProcessor extends FujiServiceNowProcessor { + FujiServiceNowTableProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + } + + @Override + protected void doProcess(Exchange exchange, Class<?> model, String action, String tableName, String sysId) throws Exception { + Response response; + if (ObjectHelper.equal(ServiceNowConstants.ACTION_RETRIEVE, action, true)) { + response = retrieveRecord(exchange.getIn(), model, tableName, sysId); + } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_CREATE, action, true)) { + response = createRecord(exchange.getIn(), model, tableName); + } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_MODIFY, action, true)) { + response = modifyRecord(exchange.getIn(), model, tableName, sysId); + } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_DELETE, action, true)) { + response = deleteRecord(exchange.getIn(), model, tableName, sysId); + } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_UPDATE, action, true)) { + response = updateRecord(exchange.getIn(), model, tableName, sysId); + } else { + throw new IllegalArgumentException("Unknown action " + action); + } + + setBodyAndHeaders(exchange.getIn(), model, response); + } + + /* + * GET + * https://instance.service-now.com/api/now/table/{tableName} + * https://instance.service-now.com/api/now/table/{tableName}/{sys_id} + */ + private Response retrieveRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception { + return ObjectHelper.isEmpty(sysId) + ? client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .query(ServiceNowParams.SYSPARM_QUERY, in) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_LIMIT, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.GET) + : client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .path(sysId) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.GET); + } + + /* + * POST + * https://instance.service-now.com/api/now/table/{tableName} + */ + private Response createRecord(Message in, Class<?> model, String tableName) throws Exception { + validateBody(in, model); + return client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_INPUT_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.POST, in.getMandatoryBody()); + } + + /* + * PUT + * https://instance.service-now.com/api/now/table/{tableName}/{sys_id} + */ + private Response modifyRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception { + validateBody(in, model); + return client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .path(ObjectHelper.notNull(sysId, "sysId")) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_INPUT_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.PUT, in.getMandatoryBody()); + } + + /* + * DELETE + * https://instance.service-now.com/api/now/table/{tableName}/{sys_id} + */ + private Response deleteRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception { + return client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .path(ObjectHelper.notNull(sysId, "sysId")) + .invoke(HttpMethod.DELETE); + } + + /* + * PATCH + * http://instance.service-now.com/api/now/table/{tableName}/{sys_id} + */ + private Response updateRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception { + validateBody(in, model); + return client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .path(ObjectHelper.notNull(sysId, "sysId")) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_INPUT_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke("PATCH", in.getMandatoryBody()); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowAggregateProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowAggregateProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowAggregateProcessor.java new file mode 100644 index 0000000..17dbfdb --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowAggregateProcessor.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.helsinki; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; + +class HelsinkiServiceNowAggregateProcessor extends AbstractServiceNowProcessor { + + HelsinkiServiceNowAggregateProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, this::retrieveStats); + } + + /* + * This method retrieves records for the specified table and performs aggregate + * functions on the returned values. + * + * Method: + * - GET + * + * URL Format: + * - /api/now/api/stats/{tableName} + */ + private void retrieveStats(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("stats") + .path(tableName) + .query(ServiceNowParams.SYSPARM_QUERY, in) + .query(ServiceNowParams.SYSPARM_AVG_FIELDS, in) + .query(ServiceNowParams.SYSPARM_COUNT, in) + .query(ServiceNowParams.SYSPARM_MIN_FIELDS, in) + .query(ServiceNowParams.SYSPARM_QUERY, in) + .query(ServiceNowParams.SYSPARM_MAX_FIELDS, in) + .query(ServiceNowParams.SYSPARM_SUM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_GROUP_BY, in) + .query(ServiceNowParams.SYSPARM_ORDER_BY, in) + .query(ServiceNowParams.SYSPARM_HAVING, in) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowAttachmentProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowAttachmentProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowAttachmentProcessor.java new file mode 100644 index 0000000..097c220 --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowAttachmentProcessor.java @@ -0,0 +1,168 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.helsinki; + +import java.io.InputStream; +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowConstants; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; +import org.apache.camel.util.ObjectHelper; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_CONTENT; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_DELETE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_UPLOAD; + +public class HelsinkiServiceNowAttachmentProcessor extends AbstractServiceNowProcessor { + protected HelsinkiServiceNowAttachmentProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, this::retrieveMeta); + addDispatcher(ACTION_CONTENT, this::retrieveContent); + addDispatcher(ACTION_UPLOAD, this::uploadContent); + addDispatcher(ACTION_DELETE, this::deleteContent); + } + + /* + * This method gets the metadata for multiple attachments or for a specific + * attachment with a specific sys_id value + * + * Method: + * - GET + * + * URL Format: + * - /api/now/api/now/attachment + * - /api/now/api/now/attachment/{sys_id} + */ + private void retrieveMeta(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = ObjectHelper.isEmpty(sysId) + ? client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("attachment") + .query(ServiceNowParams.SYSPARM_QUERY, in) + .query(ServiceNowParams.SYSPARM_LIMIT, in) + .query(ServiceNowParams.SYSPARM_OFFSET, in) + .query(ServiceNowParams.SYSPARM_SUPPRESS_PAGINATION_HEADER, in) + .invoke(HttpMethod.GET) + : client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("attachment") + .path(ObjectHelper.notNull(sysId, "sysId")) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method gets the binary file attachment with a specific sys_id value. + * + * Method: + * - GET + * + * URL Format: + * - /api/now/attachment/{sys_id}/file + */ + private void retrieveContent(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .type(MediaType.APPLICATION_JSON_TYPE) + .accept("*/*") + .path("now") + .path("attachment") + .path(ObjectHelper.notNull(sysId, "sysId")) + .path("file") + .invoke(HttpMethod.GET); + + // Header + setHeaders(in, null, response); + + in.setBody(response.readEntity(InputStream.class)); + } + + /* + * This method uploads a binary file specified in the request body as an attachment. + * + * Method: + * - POST + * + * URL Format: + * - /api/now/api/now/attachment/file + */ + private void uploadContent(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + + Response response = client.reset() + .type(ObjectHelper.notNull( + in.getHeader(ServiceNowConstants.CONTENT_TYPE, String.class), + ServiceNowConstants.CONTENT_TYPE)) + .accept(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("attachment") + .path("file") + .query(ServiceNowParams.PARAM_FILE_NAME, in) + .query(ServiceNowParams.PARAM_TABLE_NAME, in) + .query(ServiceNowParams.PARAM_TABLE_SYS_ID, in) + .query(ServiceNowParams.PARAM_ENCRYPTION_CONTEXT, in) + .invoke(HttpMethod.POST, in.getMandatoryBody(InputStream.class)); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method deletes the attachment with a specific sys_id value. + * + * Method: + * - DELETE + * + * URL Format: + * - /api/now/attachment/{sys_id} + */ + private void deleteContent(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("attachment") + .path(ObjectHelper.notNull(sysId, "sysId")) + .invoke(HttpMethod.DELETE); + + setBodyAndHeaders(in, model, response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowImportSetProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowImportSetProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowImportSetProcessor.java new file mode 100644 index 0000000..db35b9e --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowImportSetProcessor.java @@ -0,0 +1,82 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.helsinki; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; +import org.apache.camel.util.ObjectHelper; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_CREATE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; + +class HelsinkiServiceNowImportSetProcessor extends AbstractServiceNowProcessor { + + HelsinkiServiceNowImportSetProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, this::retrieveRecord); + addDispatcher(ACTION_CREATE, this::createRecord); + } + + /* + * GET + * https://instance.service-now.com/api/now/import/{tableName}/{sys_id} + */ + private void retrieveRecord(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("import") + .path(ObjectHelper.notNull(tableName, "tableName")) + .path(ObjectHelper.notNull(sysId, "sysId")) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } + + /* + * POST + * https://instance.service-now.com/api/now/import/{tableName} + */ + private void createRecord(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + + validateBody(in, model); + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("import") + .path(tableName) + .invoke(HttpMethod.POST, in.getMandatoryBody()); + + setBodyAndHeaders(in, model, response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowMiscProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowMiscProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowMiscProcessor.java new file mode 100644 index 0000000..0511e03 --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowMiscProcessor.java @@ -0,0 +1,89 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.helsinki; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_CREATE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_IDENTIFY_RECONCILE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_USER_ROLE_INHERITANCE; + +class HelsinkiServiceNowMiscProcessor extends AbstractServiceNowProcessor { + + HelsinkiServiceNowMiscProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, ACTION_SUBJECT_USER_ROLE_INHERITANCE, this::retrieveUserRoleInheritance); + addDispatcher(ACTION_CREATE, ACTION_SUBJECT_IDENTIFY_RECONCILE, this::uploadIdentifyReconcile); + } + + /* + * This method retrieves the roles the user has an determine what was inherited. + * + * Method: + * - GET + * + * URL Format: + * - /api/global/user_role_inheritance + */ + private void retrieveUserRoleInheritance(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("global") + .path("user_role_inheritance") + .query(ServiceNowParams.PARAM_USER_SYS_ID, in) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method retrieves the roles the user has an determine what was inherited. + * + * Method: + * - POST + * + * URL Format: + * - /api/now/identifyreconcile + */ + private void uploadIdentifyReconcile(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("identifyreconcile") + .query(ServiceNowParams.SYSPARM_DATA_SOURCE, in) + .invoke(HttpMethod.POST, in.getMandatoryBody()); + + setBodyAndHeaders(in, model, response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowProducer.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowProducer.java new file mode 100644 index 0000000..941f011 --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowProducer.java @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.helsinki; + +import org.apache.camel.component.servicenow.AbstractServiceNowProducer; +import org.apache.camel.component.servicenow.ServiceNowConstants; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowRelease; + +/** + * The Helsinki ServiceNow producer. + */ +public class HelsinkiServiceNowProducer extends AbstractServiceNowProducer { + public HelsinkiServiceNowProducer(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint, ServiceNowRelease.HELSINKY); + + bind(ServiceNowConstants.RESOURCE_TABLE, new HelsinkiServiceNowTableProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_AGGREGATE, new HelsinkiServiceNowAggregateProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_IMPORT, new HelsinkiServiceNowImportSetProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_ATTACHMENT, new HelsinkiServiceNowAttachmentProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_SCORECARDS, new HelsinkiServiceNowScorecardProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_MISC, new HelsinkiServiceNowMiscProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_SERVICE_CATALOG, new HelsinkiServiceNowServiceCatalogProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_SERVICE_CATALOG_ITEMS, new HelsinkiServiceNowServiceCatalogItemsProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_SERVICE_CATALOG_CARTS, new HelsinkiServiceNowServiceCatalogCartsProcessor(endpoint)); + bind(ServiceNowConstants.RESOURCE_SERVICE_CATALOG_CATEGORIES, new HelsinkiServiceNowServiceCatalogCategoriesProcessor(endpoint)); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowScorecardProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowScorecardProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowScorecardProcessor.java new file mode 100644 index 0000000..78afa77 --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowScorecardProcessor.java @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.helsinki; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_PERFORMANCE_ANALYTICS; + +class HelsinkiServiceNowScorecardProcessor extends AbstractServiceNowProcessor { + + HelsinkiServiceNowScorecardProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, ACTION_SUBJECT_PERFORMANCE_ANALYTICS, this::retrievePerformanceAnalytics); + } + + /* + * This method retrieves Performance Analytics scorecard details. + * + * Method: + * - GET + * + * URL Format: + * - /api/now/pa/scorecards + */ + private void retrievePerformanceAnalytics(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("pa") + .path("scorecards") + .query(ServiceNowParams.SYSPARM_UUID, in) + .query(ServiceNowParams.SYSPARM_BREAKDOWN, in) + .query(ServiceNowParams.SYSPARM_INCLUDE_SCORES, in) + .query(ServiceNowParams.SYSPARM_INCLUDE_AGGREGATES, in) + .query(ServiceNowParams.SYSPARM_INCLUDE_AVAILABLE_BREAKDOWNS, in) + .query(ServiceNowParams.SYSPARM_INCLUDE_AVAILABLE_AGGREGATES, in) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FAVORITES, in) + .query(ServiceNowParams.SYSPARM_KEY, in) + .query(ServiceNowParams.SYSPARM_TARGET, in) + .query(ServiceNowParams.SYSPARM_DISPLAY, in) + .query(ServiceNowParams.SYSPARM_CONTAINS, in) + .query(ServiceNowParams.SYSPARM_TAGS, in) + .query(ServiceNowParams.SYSPARM_PER_PAGE, in) + .query(ServiceNowParams.SYSPARM_PAGE, in) + .query(ServiceNowParams.SYSPARM_SORT_BY, in) + .query(ServiceNowParams.SYSPARM_SORT_DIR, in) + .query(ServiceNowParams.SYSPARM_ELEMENTS_FILTER, in) + .query(ServiceNowParams.SYSPARM_BREAKDOWN_RELATION, in) + .query(ServiceNowParams.SYSPARM_INCLUDE_SCORE_NOTES, in) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogCartsProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogCartsProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogCartsProcessor.java new file mode 100644 index 0000000..058dc5e --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogCartsProcessor.java @@ -0,0 +1,200 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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.apache.camel.component.servicenow.releases.helsinki; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_DELETE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_CHECKOUT; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_DELIVERY_ADDRESS; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_UPDATE; + +class HelsinkiServiceNowServiceCatalogCartsProcessor extends AbstractServiceNowProcessor { + + HelsinkiServiceNowServiceCatalogCartsProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, ACTION_SUBJECT_DELIVERY_ADDRESS, this::retrieveDeliveryAddress); + addDispatcher(ACTION_RETRIEVE, ACTION_SUBJECT_CHECKOUT, this::retrieveCheckoutCart); + addDispatcher(ACTION_RETRIEVE, ACTION_SUBJECT_CHECKOUT, this::retrieveCarts); + addDispatcher(ACTION_UPDATE, ACTION_SUBJECT_CHECKOUT, this::checkoutCart); + addDispatcher(ACTION_UPDATE, this::updateCart); + addDispatcher(ACTION_DELETE, this::deleteCart); + } + + /* + * This method retrieves the default list of cart contents, cart details, + * and price shown on the two-step checkout page. + * + * Method: + * - GET + * + * URL Format: + * - /sn_sc/servicecatalog/cart + */ + private void retrieveCarts(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("cart") + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method retrieves the shipping address of the requested user. + * + * Method: + * - GET + * + * URL Format: + * - /sn_sc/servicecatalog/cart/delivery_address/{user_id} + */ + private void retrieveDeliveryAddress(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("cart") + .path("delivery_address") + .path(getMandatoryRequestParamFromHeader(ServiceNowParams.PARAM_USER_ID, in)) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method edits and updates any item in the cart. + * + * Method: + * - POST + * + * URL Format: + * - /sn_sc/servicecatalog/cart/{cart_item_id} + */ + private void updateCart(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("cart") + .path(getMandatoryRequestParamFromHeader(ServiceNowParams.PARAM_CART_ITEM_ID, in)) + .invoke(HttpMethod.POST, in.getMandatoryBody()); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method deletes the cart and contents of the cart for a given user + * role and sys_id. + * + * Method: + * - DELETE + * + * URL Format: + * - /sn_sc/servicecatalog/cart/{sys_id}/empty + */ + private void deleteCart(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("cart") + .path(getMandatoryRequestParamFromHeader(ServiceNowParams.PARAM_SYS_ID, in)) + .path("empty") + .invoke(HttpMethod.DELETE); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method retrieves the checkout cart details based on the two-step + * checkout process enabled or disabled. If the user enables two-step checkout, + * the method returns cart order status and all the information required for + * two-step checkout. If the user disables two-step checkout, the method + * checks out the cart and returns the request number and request order ID. + * + * Method: + * - POST + * + * URL Format: + * - /sn_sc/servicecatalog/cart/checkout + */ + private void retrieveCheckoutCart(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("cart") + .path("checkout") + .invoke(HttpMethod.POST); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method checks out the user cart, whether two-step parameter is + * enabled or disabled. + * + * Method: + * - POST + * + * URL Format: + * - /sn_sc/servicecatalog/cart/submit_order + */ + private void checkoutCart(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("cart") + .path("submit_order") + .invoke(HttpMethod.POST); + + setBodyAndHeaders(in, model, response); + } +}