Search in sources :

Example 6 with UntypedItemXml

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);
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) UntypedItemXml(org.platformlayer.UntypedItemXml)

Example 7 with UntypedItemXml

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;
    }
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) UntypedItemXml(org.platformlayer.UntypedItemXml) Links(org.platformlayer.core.model.Links) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Link(org.platformlayer.core.model.Link)

Example 8 with UntypedItemXml

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();
}
Also used : UntypedItemXml(org.platformlayer.UntypedItemXml) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Ansi(com.fathomdb.cli.commands.Ansi)

Example 9 with UntypedItemXml

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();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) JSONObject(org.json.JSONObject) UntypedItemXml(org.platformlayer.UntypedItemXml) UntypedItemJson(org.platformlayer.UntypedItemJson) JSONException(org.json.JSONException) Ansi(com.fathomdb.cli.commands.Ansi) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source)

Aggregations

UntypedItemXml (org.platformlayer.UntypedItemXml)9 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)4 PlatformLayerClient (org.platformlayer.PlatformLayerClient)3 UntypedItem (org.platformlayer.common.UntypedItem)3 Ansi (com.fathomdb.cli.commands.Ansi)2 Link (org.platformlayer.core.model.Link)2 Links (org.platformlayer.core.model.Links)2 Tags (org.platformlayer.core.model.Tags)2 InetAddress (java.net.InetAddress)1 Source (javax.xml.transform.Source)1 DOMSource (javax.xml.transform.dom.DOMSource)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 UntypedItemJson (org.platformlayer.UntypedItemJson)1 PlatformLayerCliContext (org.platformlayer.client.cli.PlatformLayerCliContext)1 ElementInfo (org.platformlayer.xml.XmlHelper.ElementInfo)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1