RefreshADBMobileConfig.java 3.89 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.ui.components.HtmlResponse
 *  com.day.cq.i18n.I18n
 *  javax.servlet.http.HttpServletRequest
 *  org.apache.commons.lang3.StringUtils
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ValueMap
 *  org.apache.sling.servlets.post.Modification
 *  org.slf4j.Logger
 */
package com.adobe.cq.mobile.platform.impl.operations;

import com.adobe.cq.mobile.mobilecloudservices.impl.MobileClientCloudServiceHandler;
import com.adobe.cq.mobile.platform.MobileResource;
import com.adobe.cq.mobile.platform.MobileResourceType;
import com.adobe.cq.mobile.platform.impl.operations.MobileAbstractOperation;
import com.adobe.granite.ui.components.HtmlResponse;
import com.day.cq.i18n.I18n;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.servlets.post.Modification;
import org.slf4j.Logger;

@Component(metatype=0, label="Refresh ADB Mobile Config Operation")
@Service
@Properties(value={@Property(name="sling.post.operation", value={"mobileapps:refreshADBMobileConfig"})})
public class RefreshADBMobileConfig
extends MobileAbstractOperation {
    public static final String OPERATION_NAME = "refreshADBMobileConfig";
    @Reference(target="(cloudservice.id=mobileservices)")
    private MobileClientCloudServiceHandler handler;

    @Override
    protected void perform(SlingHttpServletRequest request, HtmlResponse response, List<Modification> changes) {
        I18n i18n = new I18n((HttpServletRequest)request);
        Resource resource = request.getResource();
        MobileResource mobileResource = (MobileResource)resource.adaptTo(MobileResource.class);
        if (!mobileResource.isA(MobileResourceType.INSTANCE.getType())) {
            String message = i18n.get("Unable to resolve mobile application {0}", null, new Object[]{mobileResource.getPath()});
            this.generateError(response, message, i18n.get("Error"));
            return;
        }
        LOGGER.debug("Attempting to refresh the ADBMobileConfig.json file for the app {}", (Object)resource.getPath());
        Resource content = resource.getChild("jcr:content");
        ValueMap valueMap = content.getValueMap();
        String mobileConfig = (String)valueMap.get("mobileServiceConfig", String.class);
        if (StringUtils.isNotBlank((CharSequence)mobileConfig)) {
            Resource framework = resource.getResourceResolver().getResource(mobileConfig);
            if (framework != null) {
                this.handler.updateConfiguration(framework, null);
            }
        } else {
            LOGGER.warn("Unable to locate the mobile service config associated with the application");
        }
    }

    protected void bindHandler(MobileClientCloudServiceHandler mobileClientCloudServiceHandler) {
        this.handler = mobileClientCloudServiceHandler;
    }

    protected void unbindHandler(MobileClientCloudServiceHandler mobileClientCloudServiceHandler) {
        if (this.handler == mobileClientCloudServiceHandler) {
            this.handler = null;
        }
    }
}