io.atlasmap.actions.StringComplexFieldActions Maven / Gradle / Ivy
/**
* Copyright (C) 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.atlasmap.actions;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.regex.Pattern;
import io.atlasmap.spi.AtlasFieldAction;
import io.atlasmap.spi.AtlasActionProcessor;
import io.atlasmap.v2.Append;
import io.atlasmap.v2.Concatenate;
import io.atlasmap.v2.EndsWith;
import io.atlasmap.v2.FieldType;
import io.atlasmap.v2.Format;
import io.atlasmap.v2.GenerateUUID;
import io.atlasmap.v2.IndexOf;
import io.atlasmap.v2.LastIndexOf;
import io.atlasmap.v2.PadStringLeft;
import io.atlasmap.v2.PadStringRight;
import io.atlasmap.v2.Prepend;
import io.atlasmap.v2.ReplaceAll;
import io.atlasmap.v2.ReplaceFirst;
import io.atlasmap.v2.Split;
import io.atlasmap.v2.StartsWith;
import io.atlasmap.v2.SubString;
import io.atlasmap.v2.SubStringAfter;
import io.atlasmap.v2.SubStringBefore;
public class StringComplexFieldActions implements AtlasFieldAction {
public static final String STRING_SEPARATOR_REGEX = "^\\s+:_+=";
public static final Pattern STRING_SEPARATOR_PATTERN = Pattern.compile(STRING_SEPARATOR_REGEX);
@AtlasActionProcessor
public static String append(Append append, String input) {
if (append == null) {
throw new IllegalArgumentException("Append must be specified with a string");
}
String string = append.getString();
if (input == null && string == null) {
return null;
}
if (string == null) {
return input.toString();
}
return input == null ? string : input.toString().concat(string);
}
@AtlasActionProcessor(sourceType = FieldType.ANY)
public static String concatenate(Concatenate concat, List inputs) {
if (concat == null) {
throw new IllegalArgumentException("Concatenate must be specified with a delimiter");
}
if (inputs == null) {
return null;
}
String delim = concat.getDelimiter() == null ? "" : concat.getDelimiter();
StringBuilder builder = new StringBuilder();
boolean isFirst = true;
for (String entry : inputs) {
if (!isFirst) {
builder.append(delim);
}
if (entry != null) {
builder.append(entry);
}
isFirst =false;
}
return builder.toString();
}
@AtlasActionProcessor
public static Boolean endsWith(EndsWith endsWith, String input) {
if (endsWith == null || endsWith.getString() == null) {
throw new IllegalArgumentException("EndsWith must be specified with a string");
}
return input == null ? false : input.endsWith(endsWith.getString());
}
@AtlasActionProcessor
public static String format(Format format, List © 2015 - 2025 Weber Informatics LLC | Privacy Policy