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.common.lib.request;
20  
21  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
22  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.List;
26  import javax.ws.rs.PathParam;
27  import org.apache.syncope.common.lib.BaseBean;
28  import org.apache.syncope.common.lib.types.ResourceDeassociationAction;
29  
30  /**
31   * Resource De-association Request.
32   */
33  public class ResourceDR implements BaseBean {
34  
35      private static final long serialVersionUID = 6295778399633883767L;
36  
37      public static class Builder {
38  
39          private final ResourceDR instance;
40  
41          public Builder() {
42              this.instance = new ResourceDR();
43          }
44  
45          public Builder key(final String key) {
46              instance.setKey(key);
47              return this;
48          }
49  
50          public Builder action(final ResourceDeassociationAction action) {
51              instance.setAction(action);
52              return this;
53          }
54  
55          public Builder resource(final String resource) {
56              if (resource != null) {
57                  instance.getResources().add(resource);
58              }
59              return this;
60          }
61  
62          public Builder resources(final String... resources) {
63              instance.getResources().addAll(List.of(resources));
64              return this;
65          }
66  
67          public Builder resources(final Collection<String> resources) {
68              if (resources != null) {
69                  instance.getResources().addAll(resources);
70              }
71              return this;
72          }
73  
74          public ResourceDR build() {
75              return instance;
76          }
77      }
78  
79      private String key;
80  
81      private ResourceDeassociationAction action;
82  
83      private final List<String> resources = new ArrayList<>();
84  
85      public String getKey() {
86          return key;
87      }
88  
89      @PathParam("key")
90      public void setKey(final String key) {
91          this.key = key;
92      }
93  
94      public ResourceDeassociationAction getAction() {
95          return action;
96      }
97  
98      @PathParam("action")
99      public void setAction(final ResourceDeassociationAction action) {
100         this.action = action;
101     }
102 
103     @JacksonXmlElementWrapper(localName = "resources")
104     @JacksonXmlProperty(localName = "resource")
105     public List<String> getResources() {
106         return resources;
107     }
108 }