Search in sources :

Example 1 with Links

use of org.platformlayer.core.model.Links 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();
}
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 2 with Links

use of org.platformlayer.core.model.Links 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)

Aggregations

PlatformLayerClient (org.platformlayer.PlatformLayerClient)2 UntypedItemXml (org.platformlayer.UntypedItemXml)2 Link (org.platformlayer.core.model.Link)2 Links (org.platformlayer.core.model.Links)2 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2