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.core.keymaster.rest.cxf.service;
20  
21  import com.fasterxml.jackson.databind.JsonNode;
22  import com.fasterxml.jackson.databind.json.JsonMapper;
23  import java.io.IOException;
24  import java.io.InputStream;
25  import java.util.Map;
26  import javax.ws.rs.core.Response;
27  import org.apache.syncope.common.keymaster.rest.api.service.ConfParamService;
28  import org.apache.syncope.core.logic.ConfParamLogic;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  import org.springframework.stereotype.Service;
32  
33  @Service
34  public class ConfParamServiceImpl implements ConfParamService {
35  
36      private static final long serialVersionUID = 3954522705963997651L;
37  
38      protected static final Logger LOG = LoggerFactory.getLogger(ConfParamService.class);
39  
40      private static final JsonMapper MAPPER = JsonMapper.builder().findAndAddModules().build();
41  
42      protected final ConfParamLogic logic;
43  
44      public ConfParamServiceImpl(final ConfParamLogic logic) {
45          this.logic = logic;
46      }
47  
48      @Override
49      public Map<String, Object> list() {
50          return logic.list();
51      }
52  
53      @Override
54      public Response get(final String key) {
55          return Response.ok(logic.get(key)).build();
56      }
57  
58      @Override
59      public void set(final String key, final InputStream value) {
60          JsonNode valueNode = null;
61          try {
62              valueNode = MAPPER.readTree(value);
63          } catch (IOException e) {
64              LOG.error("Could not deserialize body as valid JSON", e);
65          }
66  
67          logic.set(key, valueNode);
68      }
69  
70      @Override
71      public void remove(final String key) {
72          logic.remove(key);
73      }
74  }