}
public void setUniqueTags(PlatformLayerKey key, Iterable<Tag> uniqueTags) throws OpsException {
Tags tags = getItemTags(key);
TagChanges tagChanges = new TagChanges();
for (Tag setTag : uniqueTags) {
String tagKey = setTag.getKey();
List<String> existing = tags.findAll(tagKey);
if (existing == null || existing.isEmpty()) {
tagChanges.addTags.add(setTag);
} else if (existing.size() == 1) {
String existingValue = existing.get(0);
if (!Objects.equal(existingValue, setTag.value)) {
tagChanges.addTags.add(setTag);
tagChanges.removeTags.add(Tag.build(tagKey, existingValue));
}
} else {
// We probably should replace existing tags...
throw new OpsException("Found duplicate tag for: " + setTag.key);
}
}
if (!tagChanges.isEmpty()) {
changeTags(key, tagChanges);
}
}