Class MarketplaceServiceInternalImpl
- java.lang.Object
-
- org.craftercms.studio.impl.v2.service.marketplace.internal.MarketplaceServiceInternalImpl
-
- All Implemented Interfaces:
MarketplaceServiceInternal
,org.springframework.beans.factory.InitializingBean
public class MarketplaceServiceInternalImpl extends Object implements MarketplaceServiceInternal, org.springframework.beans.factory.InitializingBean
Default implementation ofMarketplaceServiceInternal
that proxies all request to the configured Marketplace- Since:
- 3.1.2
- Author:
- joseross
-
-
Field Summary
Fields Modifier and Type Field Description protected ConfigurationService
configurationService
static String
CONTENT_TYPE_PATTERN_CONFIG_KEY
protected ContentService
contentService
protected String
contentTypePattern
Regular expression used to detect content-type definition filesprotected ContentTypeService
contentTypeService
protected DependencyService
dependencyService
protected DeploymentService
deploymentService
protected String
edition
The current CrafterCMS edition, sent with all requestsstatic String
FOLDER_MAPPING_CONFIG_KEY
protected Map<String,String>
folderMapping
Folder mappings to use during plugin installationprotected GitRepositoryHelper
gitRepositoryHelper
protected org.springframework.http.HttpHeaders
httpHeaders
The custom HTTP headers to sent with all requestsstatic String
INSTALLABLE_TYPES_CONFIG_KEY
protected List<String>
installableTypes
List of plugin types that can be installedprotected InstanceService
instanceService
protected ReadWriteLock
lock
protected com.fasterxml.jackson.databind.ObjectMapper
mapper
static String
MODULE_CONFIG_KEY
static String
PARAM_NEW_XML
static String
PARAM_PARENT_XPATH
static String
PARAM_PLUGIN_ID
static String
PARAM_PLUGIN_PATH
static String
PATH_CONFIG_KEY
static String
PLUGIN_CONFIG_FILENAME_CONFIG_KEY
static String
PLUGIN_CONFIG_MODULE_CONFIG_KEY
static String
PLUGIN_PATTERN_KEY
protected String
pluginConfigFilename
protected String
pluginConfigModule
protected String
pluginDescriptorFilename
protected org.craftercms.commons.plugin.PluginDescriptorReader
pluginDescriptorReader
protected String
pluginRegistryPath
The path of the plugin registry in the siteprotected String
pluginsFolder
Name of the folder to copy all plugin filesprotected Lock
readLock
protected org.craftercms.commons.rest.RestTemplate
restTemplate
protected RetryingRepositoryOperationFacade
retryingRepositoryOperationFacade
protected boolean
showPending
Indicates if the search should include plugins pending of approvalprotected SiteService
siteService
protected SitesService
sitesServiceInternal
protected StudioConfiguration
studioConfiguration
static String
SYSTEM_PATH_KEY
static String
TEMPLATE_CONFIG_KEY
static String
TEMPLATE_MAPPING_CONFIG_KEY
protected String
templateCode
Code injected in the templates for each pluginprotected String
templateComment
Comment added in the templates for each pluginprotected Map<String,String>
templateMapping
Mapping used to wire plugin files into the site templatesprotected String
url
The Marketplace URL to useprotected String
version
The current CrafterCMS version, sent with all requestsstatic String
WIDGET_MAPPING_CONFIG_KEY
static String
WIDGET_REMOVE_CONFIG_KEY
protected org.apache.commons.configuration2.HierarchicalConfiguration<?>
widgetMapping
Mapping used to wire plugin files into the site configurationprotected org.springframework.core.io.Resource
widgetRemoveTemplate
XSLT template used to remove wired configurationsprotected Lock
writeLock
-
Fields inherited from interface org.craftercms.studio.api.v2.service.marketplace.internal.MarketplaceServiceInternal
HEADER_JAVA_VERSION, HEADER_OS_ARCH, HEADER_OS_NAME, HEADER_OS_VERSION, HEADER_STUDIO_BUILD, HEADER_STUDIO_ID, HEADER_STUDIO_VERSION
-
-
Constructor Summary
Constructors Constructor Description MarketplaceServiceInternalImpl(InstanceService instanceService, SiteService siteService, SitesService sitesServiceInternal, ContentService contentService, StudioConfiguration studioConfiguration, org.craftercms.commons.plugin.PluginDescriptorReader pluginDescriptorReader, GitRepositoryHelper gitRepositoryHelper, String pluginDescriptorFilename, String templateCode, String templateComment, RetryingRepositoryOperationFacade retryingRepositoryOperationFacade, DeploymentService deploymentService, DependencyService dependencyService, ContentTypeService contentTypeService, ConfigurationService configurationService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addIncludeIfNeeded(String siteId, String pluginId, List<String> paths, String includePath, String includeComment, String pluginPath, List<String> changedFiles)
protected void
addPluginToRegistry(String siteId, org.craftercms.commons.plugin.model.Plugin plugin, List<FileRecord> files, List<ConfigRecord> wiring)
void
afterPropertiesSet()
protected org.dom4j.Element
buildXml(org.craftercms.commons.plugin.model.Installation.Element element)
protected void
clonePluginFromGit(MarketplacePlugin plugin, Path directory)
protected void
commitChanges(String siteId, List<String> changedFiles, boolean update, boolean publish, String message)
void
copyPlugin(String siteId, String localPath, Map<String,String> parameters)
Copy a plugin in a siteprotected List<FileRecord>
copyPluginFiles(Path pluginDir, String siteId, org.craftercms.commons.plugin.model.Plugin plugin, Map<String,String> params)
protected void
createPluginConfig(Path siteDir, String pluginId, Map<String,String> parameters, List<String> changedFiles)
void
createSite(CreateSiteRequest request)
Creates a site using the given blueprintprotected String
getConfigurationPath(String module, String filePath)
protected MarketplacePlugin
getDescriptor(String id, org.craftercms.commons.plugin.model.Version version)
List<PluginRecord>
getInstalledPlugins(String siteId)
Returns a list of the plugins currently installed in the given siteorg.apache.commons.configuration2.HierarchicalConfiguration<?>
getPluginConfiguration(String siteId, String pluginId)
Load the configuration for a given plugin as an objectString
getPluginConfigurationAsString(String siteId, String pluginId)
Load the configuration for a given plugin as a stringprotected Optional<PluginRecord>
getPluginRecord(String siteId, String pluginId)
protected PluginRegistry
getPluginRegistry(String siteId)
List<String>
getPluginUsage(String siteId, String pluginId)
List dependant items for a pluginprotected Path
getRepoDirectory(String siteId)
void
installPlugin(String siteId, String pluginId, org.craftercms.commons.plugin.model.Version pluginVersion, Map<String,String> parameters)
Install a plugin in a siteprotected boolean
isPluginAlreadyInstalled(String siteId, String pluginId)
protected void
performConfigurationWiring(org.craftercms.commons.plugin.model.Plugin plugin, String siteId, List<String> changedFiles, List<ConfigRecord> wiring)
protected void
performTemplateWiring(org.craftercms.commons.plugin.model.Plugin plugin, String siteId, List<FileRecord> files, List<String> changedFiles)
protected void
removeConfigurationWiring(String pluginId, String siteId, List<String> changedFiles, List<ConfigRecord> changedConfigurations)
void
removePlugin(String siteId, String pluginId, boolean force)
Removes a plugin from a siteprotected void
removePluginConfig(Path siteDir, String pluginId, List<String> changedFiles)
protected void
removePluginFromRegistry(String siteId, String pluginId)
protected void
removeTemplateWiring(String pluginId, String siteId, List<String> changedFiles)
protected void
resetChanges(String siteId, List<String> changedFiles)
Map<String,Object>
searchPlugins(String type, String keywords, boolean showIncompatible, long offset, long limit)
Performs a search for all available plugins that match the given filtersvoid
setPluginRegistryPath(String pluginRegistryPath)
void
setPluginsFolder(String pluginsFolder)
void
setShowPending(boolean showPending)
void
setUrl(String url)
protected void
validate()
void
writePluginConfiguration(String siteId, String pluginId, String content)
Writes the configuration for a given plugin
-
-
-
Field Detail
-
INSTALLABLE_TYPES_CONFIG_KEY
public static final String INSTALLABLE_TYPES_CONFIG_KEY
- See Also:
- Constant Field Values
-
FOLDER_MAPPING_CONFIG_KEY
public static final String FOLDER_MAPPING_CONFIG_KEY
- See Also:
- Constant Field Values
-
WIDGET_MAPPING_CONFIG_KEY
public static final String WIDGET_MAPPING_CONFIG_KEY
- See Also:
- Constant Field Values
-
WIDGET_REMOVE_CONFIG_KEY
public static final String WIDGET_REMOVE_CONFIG_KEY
- See Also:
- Constant Field Values
-
TEMPLATE_MAPPING_CONFIG_KEY
public static final String TEMPLATE_MAPPING_CONFIG_KEY
- See Also:
- Constant Field Values
-
CONTENT_TYPE_PATTERN_CONFIG_KEY
public static final String CONTENT_TYPE_PATTERN_CONFIG_KEY
- See Also:
- Constant Field Values
-
PLUGIN_CONFIG_MODULE_CONFIG_KEY
public static final String PLUGIN_CONFIG_MODULE_CONFIG_KEY
- See Also:
- Constant Field Values
-
PLUGIN_CONFIG_FILENAME_CONFIG_KEY
public static final String PLUGIN_CONFIG_FILENAME_CONFIG_KEY
- See Also:
- Constant Field Values
-
MODULE_CONFIG_KEY
public static final String MODULE_CONFIG_KEY
- See Also:
- Constant Field Values
-
PATH_CONFIG_KEY
public static final String PATH_CONFIG_KEY
- See Also:
- Constant Field Values
-
TEMPLATE_CONFIG_KEY
public static final String TEMPLATE_CONFIG_KEY
- See Also:
- Constant Field Values
-
SYSTEM_PATH_KEY
public static final String SYSTEM_PATH_KEY
- See Also:
- Constant Field Values
-
PLUGIN_PATTERN_KEY
public static final String PLUGIN_PATTERN_KEY
- See Also:
- Constant Field Values
-
PARAM_NEW_XML
public static final String PARAM_NEW_XML
- See Also:
- Constant Field Values
-
PARAM_PARENT_XPATH
public static final String PARAM_PARENT_XPATH
- See Also:
- Constant Field Values
-
PARAM_PLUGIN_ID
public static final String PARAM_PLUGIN_ID
- See Also:
- Constant Field Values
-
PARAM_PLUGIN_PATH
public static final String PARAM_PLUGIN_PATH
- See Also:
- Constant Field Values
-
instanceService
protected final InstanceService instanceService
-
siteService
protected final SiteService siteService
-
sitesServiceInternal
protected final SitesService sitesServiceInternal
-
contentService
protected final ContentService contentService
-
studioConfiguration
protected final StudioConfiguration studioConfiguration
-
gitRepositoryHelper
protected final GitRepositoryHelper gitRepositoryHelper
-
pluginDescriptorReader
protected final org.craftercms.commons.plugin.PluginDescriptorReader pluginDescriptorReader
-
pluginDescriptorFilename
protected final String pluginDescriptorFilename
-
restTemplate
protected final org.craftercms.commons.rest.RestTemplate restTemplate
-
mapper
protected com.fasterxml.jackson.databind.ObjectMapper mapper
-
lock
protected final ReadWriteLock lock
-
readLock
protected final Lock readLock
-
writeLock
protected final Lock writeLock
-
configurationService
protected final ConfigurationService configurationService
-
httpHeaders
protected org.springframework.http.HttpHeaders httpHeaders
The custom HTTP headers to sent with all requests
-
version
protected String version
The current CrafterCMS version, sent with all requests
-
edition
protected String edition
The current CrafterCMS edition, sent with all requests
-
url
protected String url
The Marketplace URL to use
-
pluginRegistryPath
protected String pluginRegistryPath
The path of the plugin registry in the site
-
showPending
protected boolean showPending
Indicates if the search should include plugins pending of approval
-
folderMapping
protected final Map<String,String> folderMapping
Folder mappings to use during plugin installation
-
pluginsFolder
protected String pluginsFolder
Name of the folder to copy all plugin files
-
widgetMapping
protected org.apache.commons.configuration2.HierarchicalConfiguration<?> widgetMapping
Mapping used to wire plugin files into the site configuration
-
widgetRemoveTemplate
protected org.springframework.core.io.Resource widgetRemoveTemplate
XSLT template used to remove wired configurations
-
templateMapping
protected Map<String,String> templateMapping
Mapping used to wire plugin files into the site templates
-
templateCode
protected String templateCode
Code injected in the templates for each plugin
-
templateComment
protected String templateComment
Comment added in the templates for each plugin
-
contentTypePattern
protected String contentTypePattern
Regular expression used to detect content-type definition files
-
pluginConfigModule
protected String pluginConfigModule
-
pluginConfigFilename
protected String pluginConfigFilename
-
retryingRepositoryOperationFacade
protected RetryingRepositoryOperationFacade retryingRepositoryOperationFacade
-
deploymentService
protected final DeploymentService deploymentService
-
dependencyService
protected final DependencyService dependencyService
-
contentTypeService
protected final ContentTypeService contentTypeService
-
-
Constructor Detail
-
MarketplaceServiceInternalImpl
@ConstructorProperties({"instanceService","siteService","sitesServiceInternal","contentService","studioConfiguration","pluginDescriptorReader","gitRepositoryHelper","pluginDescriptorFilename","templateCode","templateComment","retryingRepositoryOperationFacade","deploymentService","dependencyService","contentTypeService","configurationService"}) public MarketplaceServiceInternalImpl(InstanceService instanceService, SiteService siteService, SitesService sitesServiceInternal, ContentService contentService, StudioConfiguration studioConfiguration, org.craftercms.commons.plugin.PluginDescriptorReader pluginDescriptorReader, GitRepositoryHelper gitRepositoryHelper, String pluginDescriptorFilename, String templateCode, String templateComment, RetryingRepositoryOperationFacade retryingRepositoryOperationFacade, DeploymentService deploymentService, DependencyService dependencyService, ContentTypeService contentTypeService, ConfigurationService configurationService)
-
-
Method Detail
-
setUrl
public void setUrl(String url)
-
setPluginRegistryPath
public void setPluginRegistryPath(String pluginRegistryPath)
-
setShowPending
public void setShowPending(boolean showPending)
-
setPluginsFolder
public void setPluginsFolder(String pluginsFolder)
-
afterPropertiesSet
public void afterPropertiesSet() throws IOException
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
IOException
-
searchPlugins
public Map<String,Object> searchPlugins(String type, String keywords, boolean showIncompatible, long offset, long limit) throws MarketplaceException
Description copied from interface:MarketplaceServiceInternal
Performs a search for all available plugins that match the given filters- Specified by:
searchPlugins
in interfaceMarketplaceServiceInternal
- Parameters:
type
- the type of plugins to searchkeywords
- the keywords to filter pluginsshowIncompatible
- indicates if incompatible plugins should be returnedoffset
- the offset for paginationlimit
- the limit for pagination- Returns:
- the result from the Marketplace
- Throws:
MarketplaceException
- if there is any error performing the search
-
validate
protected void validate() throws MarketplaceException
- Throws:
MarketplaceException
-
getDescriptor
protected MarketplacePlugin getDescriptor(String id, org.craftercms.commons.plugin.model.Version version) throws MarketplaceException
- Throws:
MarketplaceException
-
createSite
public void createSite(CreateSiteRequest request) throws RemoteRepositoryNotFoundException, InvalidRemoteRepositoryException, InvalidRemoteUrlException, ServiceLayerException, InvalidRemoteRepositoryCredentialsException
Description copied from interface:MarketplaceServiceInternal
Creates a site using the given blueprint- Specified by:
createSite
in interfaceMarketplaceServiceInternal
- Parameters:
request
- the site information- Throws:
RemoteRepositoryNotFoundException
- if there is an error with the remote repositoryInvalidRemoteRepositoryException
- if there is an error with the remote repositoryInvalidRemoteUrlException
- if there is an error with the remote repositoryServiceLayerException
- if there is any unexpected errorInvalidRemoteRepositoryCredentialsException
- if there is any error with the credentials
-
getInstalledPlugins
public List<PluginRecord> getInstalledPlugins(String siteId) throws MarketplaceException
Description copied from interface:MarketplaceServiceInternal
Returns a list of the plugins currently installed in the given site- Specified by:
getInstalledPlugins
in interfaceMarketplaceServiceInternal
- Parameters:
siteId
- the id of the site- Returns:
- the list of plugins
- Throws:
MarketplaceException
- if there is any error reading the plugin registry
-
getPluginRegistry
protected PluginRegistry getPluginRegistry(String siteId) throws MarketplaceRegistryException
- Throws:
MarketplaceRegistryException
-
installPlugin
public void installPlugin(String siteId, String pluginId, org.craftercms.commons.plugin.model.Version pluginVersion, Map<String,String> parameters) throws MarketplaceException
Description copied from interface:MarketplaceServiceInternal
Install a plugin in a site- Specified by:
installPlugin
in interfaceMarketplaceServiceInternal
- Parameters:
siteId
- the id of the sitepluginId
- the id of the pluginpluginVersion
- the version of the pluginparameters
- the parameters for the plugin- Throws:
MarketplaceException
- if there is any error installing the plugin
-
isPluginAlreadyInstalled
protected boolean isPluginAlreadyInstalled(String siteId, String pluginId) throws MarketplaceException
- Throws:
MarketplaceException
-
clonePluginFromGit
protected void clonePluginFromGit(MarketplacePlugin plugin, Path directory) throws PluginInstallationException
- Throws:
PluginInstallationException
-
copyPluginFiles
protected List<FileRecord> copyPluginFiles(Path pluginDir, String siteId, org.craftercms.commons.plugin.model.Plugin plugin, Map<String,String> params) throws IOException
- Throws:
IOException
-
addPluginToRegistry
protected void addPluginToRegistry(String siteId, org.craftercms.commons.plugin.model.Plugin plugin, List<FileRecord> files, List<ConfigRecord> wiring) throws MarketplaceRegistryException, IOException
-
removePluginFromRegistry
protected void removePluginFromRegistry(String siteId, String pluginId) throws MarketplaceRegistryException, IOException
-
copyPlugin
public void copyPlugin(String siteId, String localPath, Map<String,String> parameters) throws MarketplaceException
Description copied from interface:MarketplaceServiceInternal
Copy a plugin in a site- Specified by:
copyPlugin
in interfaceMarketplaceServiceInternal
- Parameters:
siteId
- the id of the sitelocalPath
- the path of the plugin folderparameters
- the parameters for the plugin- Throws:
MarketplaceException
- if there is any error copying the plugin
-
removePlugin
public void removePlugin(String siteId, String pluginId, boolean force) throws ServiceLayerException
Description copied from interface:MarketplaceServiceInternal
Removes a plugin from a site- Specified by:
removePlugin
in interfaceMarketplaceServiceInternal
- Parameters:
siteId
- the id of the sitepluginId
- the id of the pluginforce
- indicates if the plugin should be removed even if there are dependant items- Throws:
MarketplaceException
- if there is any error removing the pluginServiceLayerException
-
getPluginConfiguration
public org.apache.commons.configuration2.HierarchicalConfiguration<?> getPluginConfiguration(String siteId, String pluginId) throws ConfigurationException
Description copied from interface:MarketplaceServiceInternal
Load the configuration for a given plugin as an object- Specified by:
getPluginConfiguration
in interfaceMarketplaceServiceInternal
- Parameters:
siteId
- the id of the sitepluginId
- the id of the plugin- Returns:
- the configuration object
- Throws:
ConfigurationException
- if there is any error loading the configuration
-
getPluginConfigurationAsString
public String getPluginConfigurationAsString(String siteId, String pluginId) throws ContentNotFoundException
Description copied from interface:MarketplaceServiceInternal
Load the configuration for a given plugin as a string- Specified by:
getPluginConfigurationAsString
in interfaceMarketplaceServiceInternal
- Parameters:
siteId
- the id of the sitepluginId
- the id of the plugin- Returns:
- the configuration string
- Throws:
ContentNotFoundException
- if there is any issue reading the file from the repository
-
writePluginConfiguration
public void writePluginConfiguration(String siteId, String pluginId, String content) throws UserNotFoundException, ServiceLayerException
Description copied from interface:MarketplaceServiceInternal
Writes the configuration for a given plugin- Specified by:
writePluginConfiguration
in interfaceMarketplaceServiceInternal
- Parameters:
siteId
- the id of the sitepluginId
- the id of the plugincontent
- the new configuration- Throws:
UserNotFoundException
- if there is any error authenticating the userServiceLayerException
- if there is any error writing the configuration
-
createPluginConfig
protected void createPluginConfig(Path siteDir, String pluginId, Map<String,String> parameters, List<String> changedFiles) throws IOException, org.apache.commons.configuration2.ex.ConfigurationException
- Throws:
IOException
org.apache.commons.configuration2.ex.ConfigurationException
-
removePluginConfig
protected void removePluginConfig(Path siteDir, String pluginId, List<String> changedFiles) throws IOException
- Throws:
IOException
-
getPluginRecord
protected Optional<PluginRecord> getPluginRecord(String siteId, String pluginId) throws MarketplaceRegistryException
- Throws:
MarketplaceRegistryException
-
getPluginUsage
public List<String> getPluginUsage(String siteId, String pluginId) throws ServiceLayerException
Description copied from interface:MarketplaceServiceInternal
List dependant items for a plugin- Specified by:
getPluginUsage
in interfaceMarketplaceServiceInternal
- Parameters:
siteId
- the id of the sitepluginId
- the id of the plugin- Throws:
ServiceLayerException
- if there is any error getting the dependant items
-
resetChanges
protected void resetChanges(String siteId, List<String> changedFiles) throws IOException, org.eclipse.jgit.api.errors.GitAPIException
- Throws:
IOException
org.eclipse.jgit.api.errors.GitAPIException
-
commitChanges
protected void commitChanges(String siteId, List<String> changedFiles, boolean update, boolean publish, String message) throws IOException, org.eclipse.jgit.api.errors.GitAPIException, ServiceLayerException, UserNotFoundException
- Throws:
IOException
org.eclipse.jgit.api.errors.GitAPIException
ServiceLayerException
UserNotFoundException
-
performConfigurationWiring
protected void performConfigurationWiring(org.craftercms.commons.plugin.model.Plugin plugin, String siteId, List<String> changedFiles, List<ConfigRecord> wiring) throws TransformerException, IOException, ServiceLayerException, org.dom4j.DocumentException
- Throws:
TransformerException
IOException
ServiceLayerException
org.dom4j.DocumentException
-
performTemplateWiring
protected void performTemplateWiring(org.craftercms.commons.plugin.model.Plugin plugin, String siteId, List<FileRecord> files, List<String> changedFiles) throws IOException
- Throws:
IOException
-
addIncludeIfNeeded
protected void addIncludeIfNeeded(String siteId, String pluginId, List<String> paths, String includePath, String includeComment, String pluginPath, List<String> changedFiles) throws IOException
- Throws:
IOException
-
buildXml
protected org.dom4j.Element buildXml(org.craftercms.commons.plugin.model.Installation.Element element)
-
removeTemplateWiring
protected void removeTemplateWiring(String pluginId, String siteId, List<String> changedFiles) throws IOException
- Throws:
IOException
-
removeConfigurationWiring
protected void removeConfigurationWiring(String pluginId, String siteId, List<String> changedFiles, List<ConfigRecord> changedConfigurations) throws IOException, TransformerException
- Throws:
IOException
TransformerException
-
-