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.Product;
22  import org.apache.logging.log4j.catalog.jpa.model.EventModel;
23  import org.apache.logging.log4j.catalog.jpa.model.ProductModel;
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 ProductModelConverter extends AbstractConverter<ProductModel, Product> {
31  
32      @Autowired
33      private EventService eventService;
34  
35      public Product convert(ProductModel productModel) {
36          Product product = new Product();
37          product.setId(productModel.getId());
38          product.setName(productModel.getName());
39          product.setDisplayName(productModel.getDisplayName());
40          product.setDescription(productModel.getDescription());
41          product.setCatalogId(productModel.getCatalogId());
42          List<String> events = new ArrayList<>(productModel.getEvents().size());
43          for (EventModel event : productModel.getEvents()) {
44              events.add(event.getName());
45          }
46          product.setEvents(events);
47          return product;
48      }
49  }