All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.konik.csv.processor.DocumentCodeProcessor Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package io.konik.csv.processor;

import io.konik.zugferd.unece.codes.DocumentCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.util.CsvContext;

/**
 * Custom {@link CellProcessor} for {@link io.konik.zugferd.unece.codes.DocumentCode}.
 */
public final class DocumentCodeProcessor implements CellProcessor {

	private static final Logger log = LoggerFactory.getLogger(DocumentCodeProcessor.class);

	@Override
	public Object execute(Object value, CsvContext context) {

		if (value instanceof String) {
			String code = (String) value;
			try {
				return DocumentCode.getByCode(code);
			} catch (IllegalArgumentException e) {
				log.warn("DocumentCode for value {} does not exist", value);
			}
		}

		if (value instanceof DocumentCode) {
			DocumentCode code = (DocumentCode) value;
			return code.getCode();
		}

		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy