public DatasetToOperatingSystem(Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = osVersionMap;
}
public OperatingSystem apply(Dataset from) {
Builder builder = OperatingSystem.builder();
builder.name(from.getName());
builder.description(from.getUrn());
builder.is64Bit(true);// TODO: verify
String os = from.getOs();
OsFamily family = UNRECOGNIZED;
String version = "";
if (os.compareTo("smartos") == 0) {
family = fromValue(os);
version = from.getVersion();
}
else {
List<String> pieces = ImmutableList.copyOf(Splitter.on(':').split(from.getUrn()));
if (pieces.get(2).indexOf('-') != -1) {
List<String> osFamVersion = ImmutableList.copyOf(Splitter.on('-').split(pieces.get(2)));
family = fromValue(osFamVersion.get(0));
if (family != UNRECOGNIZED)
version = osFamVersion.get(1);
} else {
family = fromValue(pieces.get(2));
}
}
builder.family(family);
if (family != UNRECOGNIZED)
version = parseVersionOrReturnEmptyString(family, version, osVersionMap);
if ("".equals(version))
version = from.getVersion();
builder.version(version);
return builder.build();
}