use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.
the class FederatedPlatformLayerClient method putItemByTag.
@Override
public UntypedItem putItemByTag(PlatformLayerKey key, Tag uniqueTag, String data, Format format) throws PlatformLayerClientException {
MappedPlatformLayerKey mapped = mapToChildForPut(key);
UntypedItemXml post = UntypedItemXml.build(data);
post.setPlatformLayerKey(mapped.key);
UntypedItem item = mapped.child.client.putItemByTag(mapped.key, uniqueTag, post.serialize(), format);
return mapped.child.setHost(item);
}
use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.
the class SshAddressFinder method visit.
public void visit(UntypedItem item) throws PlatformLayerClientException {
UntypedItemXml untypedItem = (UntypedItemXml) item;
ElementInfo rootElementInfo = untypedItem.getRootElementInfo();
boolean consider = true;
switch(untypedItem.getState()) {
case DELETED:
case DELETE_REQUESTED:
consider = false;
break;
}
Set<String> instanceTypes = Sets.newHashSet();
instanceTypes.add("directInstance");
instanceTypes.add("googleCloudInstance");
if (!instanceTypes.contains(rootElementInfo.elementName)) {
consider = false;
}
if (consider) {
Tags itemTags = untypedItem.getTags();
for (InetAddress address : Tag.NETWORK_ADDRESS.find(itemTags)) {
found.add(address);
}
}
boolean includeDeleted = false;
for (UntypedItem child : client.listChildren(untypedItem.getKey(), includeDeleted).getItems()) {
visit(child);
}
}
use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.
the class UntypedItemFormatter method visit.
@Override
public void visit(CliContext contextGeneric, UntypedItem o, OutputSink sink) throws IOException {
PlatformLayerCliContext context = (PlatformLayerCliContext) contextGeneric;
LinkedHashMap<String, Object> values = Maps.newLinkedHashMap();
UntypedItemXml item = (UntypedItemXml) o;
Element dataElement = item.getDataElement();
// String xml = o.getModelData();
//
// Element documentElement;
//
// try {
// Document dom = XmlHelper.parseXmlDocument(xml, false);
// documentElement = dom.getDocumentElement();
// } catch (Exception e) {
// throw new IllegalArgumentException("Error parsing XML", e);
// }
values.put("key", Utils.formatUrl(context, item.getKey()));
values.put("state", item.getState());
Tags tags = item.getTags();
values.put("tags", tagsToString(context, tags));
NodeList childNodes = dataElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
String nodeName = node.getNodeName();
String localName = node.getLocalName();
String namespace = node.getNamespaceURI();
if (namespace.equals("http://platformlayer.org/core/v1.0")) {
if (localName.equals("tags")) {
continue;
}
if (localName.equals("key")) {
continue;
}
if (localName.equals("version")) {
continue;
}
if (localName.equals("state")) {
continue;
}
}
String text = formatCell(node);
text = Utils.reformatText(context, text);
values.put(nodeName, text);
}
sink.outputRow(values);
}
use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.
the class PutLink method runCommand.
@Override
public Object runCommand() throws PlatformLayerClientException {
PlatformLayerClient client = getPlatformLayerClient();
PlatformLayerKey resolved = path.resolve(getContext());
UntypedItemXml item = (UntypedItemXml) client.getItemUntyped(resolved, Format.XML);
Links links = item.getLinks();
Link link = new Link();
link.name = name;
link.target = target.resolve(getContext());
Link existing = links.findLink(name);
List<Link> linkList = links.getLinks();
if (existing != null) {
linkList.remove(existing);
}
linkList.add(link);
item.setLinks(links);
String xml = item.serialize();
UntypedItemXml updated = (UntypedItemXml) client.putItem(resolved, xml, Format.XML);
return updated.getLinks().getLinks();
}
use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.
the class ItemMutatorCommand method runCommand.
protected UntypedItemXml runCommand(ItemPath path) throws PlatformLayerClientException {
PlatformLayerClient client = getPlatformLayerClient();
PlatformLayerKey resolved = path.resolve(getContext());
UntypedItemXml item = (UntypedItemXml) client.getItemUntyped(resolved, Format.XML);
changeItem(item);
String xml = item.serialize();
UntypedItemXml updated = (UntypedItemXml) client.putItem(resolved, xml, Format.XML);
return updated;
}
Aggregations