RegistrationResource.java 1.58 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.SyntheticResource
 *  org.apache.sling.api.resource.ValueMap
 *  org.apache.sling.api.wrappers.ValueMapDecorator
 */
package com.adobe.cq.screens.impl.rest;

import com.adobe.cq.screens.device.registration.PendingDevice;
import java.util.HashMap;
import java.util.Map;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.SyntheticResource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;

public class RegistrationResource
extends SyntheticResource {
    public static final String RESOURCE_TYPE = "screens/core/components/registration";
    private final PendingDevice device;

    public RegistrationResource(ResourceResolver resolver, String path, PendingDevice device) {
        super(resolver, path, "screens/core/components/registration");
        this.device = device;
    }

    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
        if (type == ValueMap.class) {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("token", this.device.getToken());
            String code = this.device.getRegistrationCode();
            if (code != null) {
                map.put("code", code);
            }
            map.put("state", this.device.getState().name());
            return (AdapterType)new ValueMapDecorator(map);
        }
        return (AdapterType)super.adaptTo(type);
    }
}