com.enonic.xp.lib.schema.UpdateDynamicStylesHandler Maven / Gradle / Ivy
package com.enonic.xp.lib.schema;
import java.util.function.Supplier;
import com.enonic.xp.app.ApplicationKey;
import com.enonic.xp.lib.schema.mapper.StyleDescriptorMapper;
import com.enonic.xp.resource.DynamicSchemaResult;
import com.enonic.xp.resource.DynamicSchemaService;
import com.enonic.xp.resource.UpdateDynamicStylesParams;
import com.enonic.xp.script.bean.BeanContext;
import com.enonic.xp.script.bean.ScriptBean;
import com.enonic.xp.style.StyleDescriptor;
public final class UpdateDynamicStylesHandler
implements ScriptBean
{
private String application;
private String resource;
private Supplier dynamicSchemaServiceSupplier;
public void setApplication( final String application )
{
this.application = application;
}
public void setResource( final String resource )
{
this.resource = resource;
}
public Object execute()
{
final UpdateDynamicStylesParams params =
UpdateDynamicStylesParams.create().key( ApplicationKey.from( application ) ).resource( resource ).build();
final DynamicSchemaResult result = dynamicSchemaServiceSupplier.get().updateStyles( params );
return new StyleDescriptorMapper( result.getSchema(), result.getResource() );
}
@Override
public void initialize( final BeanContext context )
{
dynamicSchemaServiceSupplier = context.getService( DynamicSchemaService.class );
}
}