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.Event;
22  import org.apache.logging.log4j.catalog.api.EventAttribute;
23  import org.apache.logging.log4j.catalog.jpa.model.EventAttributeModel;
24  import org.apache.logging.log4j.catalog.jpa.model.EventModel;
25  import org.modelmapper.AbstractConverter;
26  import org.springframework.stereotype.Component;
27  
28  /**
29   *
30   */
31  @Component
32  public class EventModelConverter extends AbstractConverter<EventModel, Event> {
33  
34      public  Event convert(EventModel model) {
35          Event event = new Event();
36          event.setName(model.getName());
37          event.setDisplayName(model.getDisplayName());
38          event.setDescription(model.getDescription());
39          event.setAliases(model.getAliases());
40          event.setId(model.getId());
41          event.setCatalogId(model.getCatalogId());
42          List<EventAttribute> attributes = new ArrayList<>();
43          if (model.getAttributes() != null) {
44              for (EventAttributeModel eventAttributeModel : model.getAttributes()) {
45                  EventAttribute eventAttribute = new EventAttribute();
46                  eventAttribute.setName(eventAttributeModel.getAttribute().getName());
47                  eventAttribute.setRequired(eventAttributeModel.isRequired());
48                  attributes.add(eventAttribute);
49              }
50          }
51          event.setAttributes(attributes);
52          return event;
53      }
54  }