CommentsResourceConverter.java 2.66 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.rest.converter.ResourceConverter
 *  com.adobe.granite.rest.converter.ResourceConverterContext
 *  com.adobe.granite.rest.converter.ResourceConverterException
 *  com.adobe.granite.rest.converter.siren.AbstractPageableSirenConverter
 *  com.adobe.reef.siren.Action
 *  com.adobe.reef.siren.Action$Method
 *  com.adobe.reef.siren.Entity
 *  com.adobe.reef.siren.Field
 *  com.adobe.reef.siren.builder.ActionBuilder
 *  com.adobe.reef.siren.builder.BuilderException
 *  com.adobe.reef.siren.builder.FieldBuilder
 *  org.apache.sling.api.resource.Resource
 *  org.slf4j.Logger
 */
package com.adobe.granite.rest.assets.impl;

import com.adobe.granite.rest.assets.impl.CommentResource;
import com.adobe.granite.rest.converter.ResourceConverter;
import com.adobe.granite.rest.converter.ResourceConverterContext;
import com.adobe.granite.rest.converter.ResourceConverterException;
import com.adobe.granite.rest.converter.siren.AbstractPageableSirenConverter;
import com.adobe.reef.siren.Action;
import com.adobe.reef.siren.Entity;
import com.adobe.reef.siren.Field;
import com.adobe.reef.siren.builder.ActionBuilder;
import com.adobe.reef.siren.builder.BuilderException;
import com.adobe.reef.siren.builder.FieldBuilder;
import java.util.List;
import org.apache.sling.api.resource.Resource;
import org.slf4j.Logger;

public class CommentsResourceConverter
extends AbstractPageableSirenConverter {
    public CommentsResourceConverter(Resource resource) {
        super(resource);
    }

    protected String[] getClazz() {
        return new String[]{"assets/asset/comments"};
    }

    protected Entity getEntity(ResourceConverterContext context, Resource child) throws ResourceConverterException {
        if (child instanceof CommentResource) {
            ResourceConverter converter = (ResourceConverter)child.adaptTo(ResourceConverter.class);
            if (converter != null) {
                return (Entity)converter.toSubEntity(context);
            }
            this.log.error("Could not adapt CommentResource to ResourceConverter");
        }
        return null;
    }

    protected List<Action> getActions(ResourceConverterContext context) throws BuilderException, ResourceConverterException {
        List actions = super.getActions(context);
        actions.add(new ActionBuilder().setName("add-comment").setHref(this.buildURL(context, this.resource.getPath() + "/comments/*", null)).setMethod(Action.Method.POST).setTitle("Add Comment").addField((Field)new FieldBuilder().setName("message").build()).addField((Field)new FieldBuilder().setName("annotationData").build()).build());
        return actions;
    }
}