View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  package org.opencastproject.adminui.impl;
22  
23  import org.osgi.service.component.annotations.Activate;
24  import org.osgi.service.component.annotations.Component;
25  import org.osgi.service.component.annotations.Modified;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import java.util.ArrayList;
30  import java.util.Arrays;
31  import java.util.List;
32  import java.util.Map;
33  import java.util.Objects;
34  
35  @Component(
36    immediate = true,
37    service = AdminUIConfiguration.class,
38    property = {
39      "service.description=Admin UI - Configuration",
40      "service.pid=org.opencastproject.adminui"
41    }
42  )
43  public class AdminUIConfiguration {
44  
45    /** The logging facility */
46    private static final Logger logger = LoggerFactory.getLogger(AdminUIConfiguration.class);
47  
48    public static final String OPT_PREVIEW_SUBTYPE = "preview.subtype";
49    private static final String OPT_RETRACT_WORKFLOW_ID = "retract.workflow.id";
50    private static final String OPT_MATCH_MANAGED_ACL_ROLE_PREFIXES = "match.managed.acl.role.prefixes";
51  
52    private static final String DEFAULT_PREVIEW_SUBTYPE = "preview";
53    private static final String DEFAULT_RETRACT_WORKFLOW_ID = "delete";
54    private static final String DEFAULT_MATCH_MANAGED_ACL_ROLE_PREFIXES = "";
55  
56    private String previewSubtype = DEFAULT_PREVIEW_SUBTYPE;
57    private String retractWorkflowId = DEFAULT_RETRACT_WORKFLOW_ID;
58    private List<String> matchManagedAclRolePrefixes = new ArrayList<>();
59  
60    public String getPreviewSubtype() {
61      return previewSubtype;
62    }
63  
64    public String getRetractWorkflowId() {
65      return retractWorkflowId;
66    }
67  
68    public List<String> getMatchManagedAclRolePrefixes() { return matchManagedAclRolePrefixes; }
69  
70    @Activate
71    @Modified
72    public void modified(Map<String, Object> properties) {
73      if (properties == null) {
74        properties = Map.of();
75      }
76  
77      // Preview subtype
78      previewSubtype = Objects.toString(properties.get(OPT_PREVIEW_SUBTYPE), DEFAULT_PREVIEW_SUBTYPE);
79      logger.debug("Preview subtype configuration set to '{}'", previewSubtype);
80  
81      // Retract workflow ID
82      retractWorkflowId = Objects.toString(properties.get(OPT_RETRACT_WORKFLOW_ID), DEFAULT_RETRACT_WORKFLOW_ID);
83      logger.debug("Retract workflow ID set to {}", retractWorkflowId);
84  
85      // Managed ACL role prefix
86      String tmp = Objects.toString(properties.get(OPT_MATCH_MANAGED_ACL_ROLE_PREFIXES),
87              DEFAULT_MATCH_MANAGED_ACL_ROLE_PREFIXES);
88      matchManagedAclRolePrefixes = Arrays.asList(tmp.split(","));
89      logger.debug("Match managed acl role prefixes set to {}", matchManagedAclRolePrefixes);
90    }
91  }