Skip to content

Commit

Permalink
Add channel link profiles
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
voruti committed Aug 8, 2021
1 parent 5ac5106 commit 2f7b1a6
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/main/java/voruti/json2config/model/json/JsonChannelLink.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
package voruti.json2config.model.json;

import com.google.gson.Gson;
import lombok.Getter;
import voruti.json2config.model.IConvertible;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
@Getter
public class JsonChannelLink implements IConvertible {

private static final Gson GSON = new Gson();
private Value value;


@Override
public String toConfigLine(String lineBefore) {
String format = "channel=\"%s\"}";
// first channel or append:
String format = "channel=\"%s\"%s}";
if (lineBefore.endsWith("}")) {
lineBefore = lineBefore.substring(0, lineBefore.length() - 1);
format = "%s, " + format;
} else {
format = "%s {" + format;
}

return String.format(format, lineBefore, String.join(":", value.channelUID.segments)).strip();
// profile:
String propertiesString = "";
if (value.configuration.properties != null) {
String profile = value.configuration.properties.get("profile");
if (profile != null && !profile.equals("system:default")) {
propertiesString = String.format("[%s]",
value.configuration.properties.entrySet().stream()
.map(propertiesEntry -> String.format("%s=%s", propertiesEntry.getKey(), GSON.toJson(propertiesEntry.getValue())))
.collect(Collectors.joining(", "))
);
}
}

return String.format(format, lineBefore, String.join(":", value.channelUID.segments), propertiesString).strip();
}


Expand All @@ -38,15 +55,7 @@ private static class ChannelUID {
}

private static class Configuration {
private Properties properties;


private static class Properties {
private String offset;
private String sourceFormat;
private String profile;
private String function;
}
private Map<String, String> properties;
}
}
}

0 comments on commit 2f7b1a6

Please sign in to comment.