use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.
the class FederatedPlatformLayerClient method putItem.
// @Override
// public <T> T getItem(final Class<T> clazz, final PlatformLayerKey key) throws PlatformLayerClientException {
// MappedPlatformLayerKey mapped = mapToChild(key);
// T item = mapped.child.client.getItem(clazz, mapped.key);
// return mapped.child.setHost(item);
// }
// @Override
// public <T> T createItem(T item) throws PlatformLayerClientException {
// PlatformLayerKey key = toKey(item);
//
// MappedPlatformLayerKey mapped = mapToChildForCreate(key);
//
// T created = mapped.child.client.createItem(item);
// return mapped.child.setHost(created);
// }
//
// @Override
// public String createItem(ServiceType serviceType, ItemType itemType, String data, Format format) throws
// PlatformLayerClientException {
// throw new UnsupportedOperationException();
//
// // PlatformLayerKey key = new PlatformLayerKey(serviceType, itemType, null);
// // MappedPlatformLayerKey mapped = mapToChild(key);
// // String s = child.client.createItem(serviceType, itemType, data, format);
// // return child.setHost(s);
// }
@Override
public UntypedItem putItem(PlatformLayerKey key, String data, Format format) throws PlatformLayerClientException {
MappedPlatformLayerKey mapped = mapToChildForPut(key);
UntypedItemXml untypedItem = UntypedItemXml.build(data);
untypedItem.setPlatformLayerKey(mapped.key);
UntypedItem item = mapped.child.client.putItem(mapped.key, untypedItem.serialize(), format);
return mapped.child.setHost(item);
}
use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.
the class DeleteLink 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 existing = links.findLink(name);
List<Link> linkList = links.getLinks();
if (existing != null) {
linkList.remove(existing);
item.setLinks(links);
String xml = item.serialize();
UntypedItemXml updated = (UntypedItemXml) client.putItem(resolved, xml, Format.XML);
return updated.getLinks().getLinks();
} else {
return linkList;
}
}
use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.
the class UntypedItemFormatter method formatItem.
public static void formatItem(UntypedItem o, Ansi ansi, boolean fullPath) {
UntypedItemXml item = (UntypedItemXml) o;
Ansi.Action action = null;
switch(item.getState()) {
case ACTIVE:
action = Ansi.TEXT_COLOR_GREEN;
break;
case BUILD_ERROR:
action = Ansi.TEXT_COLOR_RED;
break;
case DELETED:
action = Ansi.TEXT_COLOR_MAGENTA;
break;
default:
action = Ansi.TEXT_COLOR_BLUE;
break;
}
Ansi.Action undo = null;
if (action != null) {
undo = ansi.doAction(action);
}
try {
PlatformLayerKey plk = item.getKey();
if (fullPath) {
ansi.print(plk.getUrl());
} else {
ansi.print(plk.getItemId().getKey());
}
} finally {
if (undo != null) {
ansi.doAction(undo);
}
}
ansi.println();
}
use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.
the class PlatformLayerCommandRunnerBase method formatRaw.
@Override
public void formatRaw(Object o, PrintWriter writer) {
String data;
if (o instanceof UntypedItemXml) {
UntypedItemXml item = (UntypedItemXml) o;
Source src = new DOMSource(item.getRoot());
String xml = DomUtils.toXml(src, 4);
data = xml;
} else if (o instanceof UntypedItemJson) {
UntypedItemJson item = (UntypedItemJson) o;
JSONObject root = item.getRoot();
try {
data = root.toString(2);
} catch (JSONException e) {
throw new IllegalStateException("Error formatting JSON", e);
}
} else {
super.formatRaw(o, writer);
return;
}
Ansi ansi = new Ansi(writer);
ansi.print(data);
ansi.println();
ansi.reset();
}
Aggregations