001/** 002 * Copyright (C) 2006-2023 Talend Inc. - www.talend.com 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.talend.sdk.component.sample; 017 018import java.io.IOException; 019import java.io.Serializable; 020 021import org.talend.sdk.component.api.processor.ElementListener; 022import org.talend.sdk.component.api.processor.Processor; 023 024import lombok.extern.slf4j.Slf4j; 025 026@Slf4j 027@Processor(name = "mapper") 028public class PersonToUserMapper implements Serializable { 029 030 // tag::map[] 031 @ElementListener 032 public User map(final Person person) throws IOException { 033 if (log.isDebugEnabled()) { 034 log.debug("Handling {}", person); 035 } 036 return new User(generateId(person), person.getName()); 037 } 038 // end::map[] 039 040 private String generateId(final Person person) { 041 // make it look like an AD convention for the sample 042 return "a" + person.getAge() + person.getName(); 043 } 044}