View Javadoc
1   /*
2    * Copyright 2001-2005 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.logging.log4j.catalog.jpa.converter;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.logging.log4j.catalog.api.Category;
22  import org.apache.logging.log4j.catalog.jpa.model.CategoryModel;
23  import org.apache.logging.log4j.catalog.jpa.model.EventModel;
24  import org.apache.logging.log4j.catalog.jpa.service.EventService;
25  import org.modelmapper.AbstractConverter;
26  import org.springframework.beans.factory.annotation.Autowired;
27  import org.springframework.stereotype.Component;
28  
29  @Component
30  public class CategoryModelConverter extends AbstractConverter<CategoryModel, Category> {
31  
32      @Autowired
33      private EventService eventService;
34  
35      public Category convert(CategoryModel categoryModel) {
36          Category category = new Category();
37          category.setId(categoryModel.getId());
38          category.setCatalogId(categoryModel.getCatalogId());
39          category.setName(categoryModel.getName());
40          category.setDisplayName(categoryModel.getDisplayName());
41          category.setDescription(categoryModel.getDescription());
42          List<String> events = new ArrayList<>(categoryModel.getEvents().size());
43          for (EventModel event : categoryModel.getEvents()) {
44              events.add(event.getName());
45          }
46          category.setEvents(events);
47          return category;
48      }
49  }