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.commons;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  import java.util.stream.Collectors;
25  import org.apache.syncope.client.console.init.ClassPathScanImplementationLookup;
26  import org.apache.syncope.client.console.rest.ImplementationRestClient;
27  import org.apache.syncope.common.lib.policy.PullCorrelationRuleConf;
28  import org.apache.syncope.common.lib.policy.PushCorrelationRuleConf;
29  import org.apache.syncope.common.lib.to.ImplementationTO;
30  import org.apache.syncope.common.lib.types.IdMImplementationType;
31  import org.apache.wicket.model.IModel;
32  import org.apache.wicket.model.LoadableDetachableModel;
33  
34  public class IdMImplementationInfoProvider extends IdRepoImplementationInfoProvider {
35  
36      private static final long serialVersionUID = -5385695412826366167L;
37  
38      public IdMImplementationInfoProvider(
39              final ClassPathScanImplementationLookup lookup,
40              final ImplementationRestClient implementationRestClient) {
41  
42          super(lookup, implementationRestClient);
43      }
44  
45      @Override
46      public ViewMode getViewMode(final ImplementationTO implementation) {
47          return IdMImplementationType.PULL_CORRELATION_RULE.equals(implementation.getType())
48                  || IdMImplementationType.PUSH_CORRELATION_RULE.equals(implementation.getType())
49                  ? ViewMode.JSON_BODY
50                  : super.getViewMode(implementation);
51      }
52  
53      @Override
54      public List<String> getClasses(final ImplementationTO implementation, final ViewMode viewMode) {
55          List<String> classes = new ArrayList<>();
56          if (viewMode == ViewMode.JSON_BODY && IdMImplementationType.values().containsKey(implementation.getType())) {
57              switch (implementation.getType()) {
58                  case IdMImplementationType.PULL_CORRELATION_RULE:
59                      classes = lookup.getClasses(PullCorrelationRuleConf.class).stream().
60                              map(Class::getName).collect(Collectors.toList());
61                      break;
62  
63                  case IdMImplementationType.PUSH_CORRELATION_RULE:
64                      classes = lookup.getClasses(PushCorrelationRuleConf.class).stream().
65                              map(Class::getName).collect(Collectors.toList());
66                      break;
67  
68                  default:
69              }
70              Collections.sort(classes);
71          } else {
72              classes = super.getClasses(implementation, viewMode);
73          }
74  
75          return classes;
76      }
77  
78      @Override
79      public String getGroovyTemplateClassName(final String implementationType) {
80          String templateClassName;
81  
82          switch (implementationType) {
83              case IdMImplementationType.RECON_FILTER_BUILDER:
84                  templateClassName = "MyReconFilterBuilder";
85                  break;
86  
87              case IdMImplementationType.PROPAGATION_ACTIONS:
88                  templateClassName = "MyPropagationActions";
89                  break;
90  
91              case IdMImplementationType.PULL_ACTIONS:
92                  templateClassName = "MyPullActions";
93                  break;
94  
95              case IdMImplementationType.PUSH_ACTIONS:
96                  templateClassName = "MyPushActions";
97                  break;
98  
99              case IdMImplementationType.PULL_CORRELATION_RULE:
100                 templateClassName = "MyPullCorrelationRule";
101                 break;
102 
103             case IdMImplementationType.PUSH_CORRELATION_RULE:
104                 templateClassName = "MyPushCorrelationRule";
105                 break;
106 
107             case IdMImplementationType.PROVISION_SORTER:
108                 templateClassName = "MyProvisionSorter";
109                 break;
110 
111             default:
112                 templateClassName = super.getGroovyTemplateClassName(implementationType);
113         }
114 
115         return templateClassName;
116     }
117 
118     @Override
119     public Class<?> getClass(final String implementationType, final String name) {
120         Class<?> clazz;
121         switch (implementationType) {
122             case IdMImplementationType.PULL_CORRELATION_RULE:
123                 clazz = lookup.getClasses(PullCorrelationRuleConf.class).stream().
124                         filter(c -> c.getName().equals(name)).findFirst().orElse(null);
125                 break;
126 
127             case IdMImplementationType.PUSH_CORRELATION_RULE:
128                 clazz = lookup.getClasses(PushCorrelationRuleConf.class).stream().
129                         filter(c -> c.getName().equals(name)).findFirst().orElse(null);
130                 break;
131 
132             default:
133                 clazz = super.getClass(implementationType, name);
134         }
135 
136         return clazz;
137     }
138 
139     @Override
140     public IModel<List<String>> getReconFilterBuilders() {
141         return new LoadableDetachableModel<>() {
142 
143             private static final long serialVersionUID = 5275935387613157437L;
144 
145             @Override
146             protected List<String> load() {
147                 return implementationRestClient.list(IdMImplementationType.RECON_FILTER_BUILDER).stream().
148                         map(ImplementationTO::getKey).sorted().collect(Collectors.toList());
149             }
150         };
151     }
152 
153     @Override
154     public IModel<List<String>> getPullActions() {
155         return new LoadableDetachableModel<>() {
156 
157             private static final long serialVersionUID = 5275935387613157437L;
158 
159             @Override
160             protected List<String> load() {
161                 return implementationRestClient.list(IdMImplementationType.PULL_ACTIONS).stream().
162                         map(ImplementationTO::getKey).sorted().collect(Collectors.toList());
163             }
164         };
165     }
166 
167     @Override
168     public IModel<List<String>> getPushActions() {
169         return new LoadableDetachableModel<>() {
170 
171             private static final long serialVersionUID = 5275935387613157437L;
172 
173             @Override
174             protected List<String> load() {
175                 return implementationRestClient.list(IdMImplementationType.PUSH_ACTIONS).stream().
176                         map(ImplementationTO::getKey).sorted().collect(Collectors.toList());
177             }
178         };
179     }
180 }