View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.resources;
20  
21  import javax.ws.rs.NotFoundException;
22  import org.apache.syncope.client.console.rest.BpmnProcessRestClient;
23  import org.apache.syncope.client.ui.commons.Constants;
24  import org.apache.syncope.common.lib.to.BpmnProcess;
25  import org.apache.wicket.request.resource.AbstractResource;
26  import org.apache.wicket.util.string.StringValue;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  abstract class AbstractBpmnProcessResource extends AbstractResource {
31  
32      private static final long serialVersionUID = 5163553843196539019L;
33  
34      protected static final Logger LOG = LoggerFactory.getLogger(AbstractBpmnProcessResource.class);
35  
36      protected final BpmnProcessRestClient bpmnProcessRestClient;
37  
38      protected AbstractBpmnProcessResource(final BpmnProcessRestClient bpmnProcessRestClient) {
39          this.bpmnProcessRestClient = bpmnProcessRestClient;
40      }
41  
42      protected BpmnProcess getBpmnProcess(final Attributes attributes) {
43          StringValue modelId = attributes.getRequest().getQueryParameters().getParameterValue(Constants.MODEL_ID_PARAM);
44  
45          BpmnProcess bpmnProcess = modelId == null || modelId.isNull()
46                  ? null
47                  : bpmnProcessRestClient.getDefinitions().stream().
48                          filter(object -> modelId.toString().equals(object.getModelId())).findAny().orElse(null);
49          if (bpmnProcess == null) {
50              throw new NotFoundException("BPMN process with modelId " + modelId);
51          }
52  
53          return bpmnProcess;
54      }
55  }