ENTAXY-374 release 1.8.2
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>adapter</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -19,7 +19,9 @@
|
||||
*/
|
||||
package ru.entaxy.esb.platform.runtime.base.connecting.adapter.core.management;
|
||||
|
||||
public interface AdapterMBean {
|
||||
import ru.entaxy.esb.platform.base.management.core.api.RuntimeTypedMBean;
|
||||
|
||||
public interface AdapterMBean extends RuntimeTypedMBean {
|
||||
|
||||
public boolean isInited();
|
||||
|
||||
|
@ -22,8 +22,11 @@ package ru.entaxy.esb.platform.runtime.base.connecting.adapter.core.management;
|
||||
import javax.management.NotCompliantMBeanException;
|
||||
import javax.management.StandardMBean;
|
||||
|
||||
import ru.entaxy.esb.platform.base.management.core.api.EntaxyRuntimeTyped;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.adapter.core.api.Adapter;
|
||||
|
||||
//@TODO move string to constant
|
||||
@EntaxyRuntimeTyped(name = "entaxy.runtime.adapter")
|
||||
public class AdapterMBeanImpl extends StandardMBean implements AdapterMBean {
|
||||
|
||||
protected Adapter adapter;
|
||||
|
@ -24,9 +24,9 @@ import ru.entaxy.esb.platform.base.management.core.Qualifier;
|
||||
|
||||
public interface AdaptersMBean {
|
||||
|
||||
public static final String ADAPTERS_KEY = "categrory";
|
||||
public static final String ADAPTERS_KEY = "category";
|
||||
|
||||
public static final String ADAPTERS_VALUE = "adapters";
|
||||
public static final String ADAPTERS_VALUE = "adapter";
|
||||
|
||||
public static final Qualifier Q_ADAPTERS = ManagementCore.Q_PLATFORM.qualifier(ADAPTERS_KEY, ADAPTERS_VALUE);
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class AdaptersMBeanImpl extends StandardMBean implements AdaptersMBean {
|
||||
|
||||
@Activate
|
||||
public void activate(ComponentContext componentContext) {
|
||||
log.info(" >> ACTIVATE <<");
|
||||
log.debug(" >> ACTIVATE <<");
|
||||
this.bundleContext = componentContext.getBundleContext();
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>adapter</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -55,7 +55,7 @@
|
||||
"type": "pathParameter",
|
||||
"generator": "",
|
||||
"config": {
|
||||
"expession": "${destinationType}:${destinationName}"
|
||||
"expression": "${destinationType}:${destinationName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>adapter</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -665,7 +665,7 @@
|
||||
"type": "pathParameter",
|
||||
"generator": "",
|
||||
"config": {
|
||||
"expession": "${destinationType}:${destinationName}"
|
||||
"expression": "${destinationType}:${destinationName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>adapter</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -55,7 +55,7 @@
|
||||
"type": "pathParameter",
|
||||
"generator": "",
|
||||
"config": {
|
||||
"expession": "${destinationType}:${destinationName}"
|
||||
"expression": "${destinationType}:${destinationName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>adapter</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -19,6 +18,9 @@
|
||||
|
||||
<properties>
|
||||
<bundle.osgi.dynamicimport.pkg>*</bundle.osgi.dynamicimport.pkg>
|
||||
<bundle.osgi.export.pkg>ru.entaxy.platform.adapter.file</bundle.osgi.export.pkg>
|
||||
<bundle.osgi.private.pkg>template,
|
||||
ru.entaxy.adapter</bundle.osgi.private.pkg>
|
||||
<!-- <bundle.osgi.private.pkg>ru.entaxy.adapter</bundle.osgi.private.pkg>-->
|
||||
</properties>
|
||||
|
||||
@ -30,11 +32,30 @@
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Entaxy-Adapter>true</Entaxy-Adapter>
|
||||
<Entaxy-Adapter-Class/>
|
||||
<!-- Entaxy-Adapter>true</Entaxy-Adapter>
|
||||
<Entaxy-Adapter-Class / -->
|
||||
<Entaxy-Factory-Provider>true</Entaxy-Factory-Provider>
|
||||
<Entaxy-Template-Provider>true</Entaxy-Template-Provider>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-file</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-util</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
|
||||
<artifactId>base-support</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* file-adapter
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2022 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.camel.component.file.FileComponent;
|
||||
import org.apache.camel.component.file.GenericFileEndpoint;
|
||||
import org.apache.camel.util.StringHelper;
|
||||
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
|
||||
public class ExtendedFileComponent extends FileComponent {
|
||||
|
||||
protected String rootDirectory = "";
|
||||
|
||||
@Override
|
||||
protected GenericFileEndpoint<File> buildFileEndpoint(String uri, String remaining, Map<String, Object> parameters)
|
||||
throws Exception {
|
||||
|
||||
// copied from parent
|
||||
if (StringHelper.hasStartToken(remaining, "simple")) {
|
||||
throw new IllegalArgumentException("Invalid directory: " + remaining + ". Dynamic expressions with ${ } placeholders is not allowed."
|
||||
+ " Use the fileName option to set the dynamic expression.");
|
||||
}
|
||||
|
||||
String current = remaining;
|
||||
if (CommonUtils.isValid(rootDirectory)) {
|
||||
current = rootDirectory;
|
||||
if (CommonUtils.isValid(remaining) && !".".equals(remaining)) {
|
||||
if (!current.endsWith("/"))
|
||||
current += "/";
|
||||
if (remaining.startsWith("/"))
|
||||
current += remaining.substring(1);
|
||||
else
|
||||
current += remaining;
|
||||
}
|
||||
}
|
||||
log.debug("CREATING ENDPOINT FOR [{}]", current);
|
||||
return super.buildFileEndpoint(uri, current, parameters);
|
||||
}
|
||||
|
||||
public String getRootDirectory() {
|
||||
return rootDirectory;
|
||||
}
|
||||
|
||||
public void setRootDirectory(String rootDirectory) {
|
||||
this.rootDirectory = rootDirectory;
|
||||
}
|
||||
|
||||
}
|
@ -516,7 +516,7 @@
|
||||
"type": "pathParameter",
|
||||
"generator": "",
|
||||
"config": {
|
||||
"expession": "${directoryName}"
|
||||
"expression": "${directoryName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@
|
||||
[#ftl attributes={"generated.type":"blueprint"}]
|
||||
[#--
|
||||
|
||||
~~~~~~licensing~~~~~~
|
||||
file-adapter
|
||||
==========
|
||||
Copyright (C) 2020 - 2021 EmDev LLC
|
||||
==========
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
~~~~~~/licensing~~~~~~
|
||||
|
||||
--]
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
|
||||
xsi:schemaLocation="
|
||||
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"
|
||||
>
|
||||
|
||||
<service interface="org.apache.camel.Component" ref="[=objectId]">
|
||||
<service-properties>
|
||||
<entry key="connection.name" value="[=objectId]"/>
|
||||
</service-properties>
|
||||
</service>
|
||||
|
||||
<bean id="[=objectId]" class="ru.entaxy.platform.adapter.file.ExtendedFileComponent">
|
||||
[#if properties??]
|
||||
[#list properties as key, value]
|
||||
[#if !key?starts_with("##") && !key?starts_with("__")] [#-- we skip additional properties --]
|
||||
<property name="[=key]" value="[=value]"/>
|
||||
[/#if]
|
||||
[/#list]
|
||||
[/#if]
|
||||
</bean>
|
||||
|
||||
</blueprint>
|
@ -45,7 +45,7 @@
|
||||
</service-properties>
|
||||
</service>
|
||||
|
||||
<bean id="[=connection.name]" class="org.apache.camel.component.file.FileComponent">
|
||||
<bean id="[=connection.name]" class="ru.entaxy.platform.adapter.file.ExtendedFileComponent">
|
||||
[#if connection.properties??]
|
||||
[#list connection.properties as key, value]
|
||||
<property name="[=key]" value="[='$']{[=connection.configurationPid].[=key]}"/>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>adapter</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -110,7 +110,7 @@
|
||||
"type": "pathParameter",
|
||||
"generator": "",
|
||||
"config": {
|
||||
"expession": "${dataSourceName}"
|
||||
"expression": "${dataSourceName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>adapter</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -665,7 +665,7 @@
|
||||
"type": "pathParameter",
|
||||
"generator": "",
|
||||
"config": {
|
||||
"expession": "${destinationType}:${destinationName}"
|
||||
"expression": "${destinationType}:${destinationName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
|
||||
<artifactId>connecting</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>adapter</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -110,7 +110,7 @@
|
||||
"type": "pathParameter",
|
||||
"generator": "",
|
||||
"config": {
|
||||
"expession": "${dataSourceName}"
|
||||
"expression": "${dataSourceName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>adapter</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -55,7 +55,7 @@
|
||||
"type": "pathParameter",
|
||||
"generator": "",
|
||||
"config": {
|
||||
"expession": "${destinationType}:${destinationName}"
|
||||
"expression": "${destinationType}:${destinationName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
|
||||
<artifactId>connecting</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>generator</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting.generator</groupId>
|
||||
<artifactId>common-templates-collection</artifactId>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>generator</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -20,7 +20,6 @@
|
||||
<bundle.osgi.export.pkg>
|
||||
ru.entaxy.esb.platform.runtime.base.connecting.generator.ftl
|
||||
</bundle.osgi.export.pkg>
|
||||
<freemarker.version>2.3.29</freemarker.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -105,6 +105,22 @@ public class FTLGenerator extends AbstractSelfPublishGenerator<FTLGenerator>
|
||||
return generateForTemplate(template, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeneratable(Map<String, Object> properties) throws Exception {
|
||||
prepareTemplate(properties);
|
||||
if (template == null)
|
||||
return false;
|
||||
URL templateURL = template.getTemplateLocation()==null
|
||||
?FrameworkUtil.getBundle(FTLGenerator.class).getEntry(DEFAULT_TEMPLATE_PATH)
|
||||
:template.getTemplateLocation();
|
||||
try {
|
||||
Template temp = getTemplateByFullName(templateURL, template.getTemplateFullName());
|
||||
return (temp != null);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Generated generateForTemplate(ru.entaxy.base.generator.template.Template template,
|
||||
Map<String, Object> properties) throws Exception {
|
||||
|
||||
@ -194,19 +210,19 @@ public class FTLGenerator extends AbstractSelfPublishGenerator<FTLGenerator>
|
||||
if (this.template != null)
|
||||
return;
|
||||
|
||||
Map<String, Object> finalPropertes = new HashMap<>();
|
||||
finalPropertes.putAll(initialProperties);
|
||||
finalPropertes.putAll(generationProperties);
|
||||
Map<String, Object> finalProperties = new HashMap<>();
|
||||
finalProperties.putAll(initialProperties);
|
||||
finalProperties.putAll(generationProperties);
|
||||
|
||||
TemplateImpl temp = new TemplateImpl();
|
||||
temp.setBundleContext(
|
||||
(BundleContext)finalPropertes.getOrDefault(Generator.PROP_TARGET_BUNDLE_CONTEXT
|
||||
(BundleContext)finalProperties.getOrDefault(Generator.PROP_TARGET_BUNDLE_CONTEXT
|
||||
, FrameworkUtil.getBundle(FTLGenerator.class).getBundleContext())
|
||||
);
|
||||
temp.setTemplateName((String)finalPropertes.getOrDefault(PROP_TEMPLATE_NAME
|
||||
, (String)finalPropertes.getOrDefault(Generator.PROP_USAGE_TYPE
|
||||
temp.setTemplateName((String)finalProperties.getOrDefault(PROP_TEMPLATE_NAME
|
||||
, (String)finalProperties.getOrDefault(Generator.PROP_USAGE_TYPE
|
||||
, "root")));
|
||||
temp.setPath((String)finalPropertes.getOrDefault(PROP_TEMPLATE_NAME
|
||||
temp.setPath((String)finalProperties.getOrDefault(PROP_TEMPLATE_NAME
|
||||
, DEFAULT_TEMPLATE_PATH)
|
||||
);
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>generator</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -20,6 +20,7 @@
|
||||
package ru.entaxy.base.generator.template;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Template {
|
||||
|
||||
@ -29,5 +30,5 @@ public interface Template {
|
||||
public String getTemplateName();
|
||||
public String getTemplateFileName();
|
||||
public String getTemplateFullName();
|
||||
|
||||
public Map<String, String> getAdditionalProperties();
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package ru.entaxy.base.generator.template;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.slf4j.Logger;
|
||||
@ -45,6 +46,8 @@ public class TemplateImpl implements Template {
|
||||
|
||||
protected String templateLocation;
|
||||
|
||||
protected Map<String, String> additionalProperties = null;
|
||||
|
||||
public void load(ProvidedTemplate providedTemplate) {
|
||||
id = providedTemplate.getId();
|
||||
name = providedTemplate.getName();
|
||||
@ -55,6 +58,7 @@ public class TemplateImpl implements Template {
|
||||
if (!path.endsWith("/"))
|
||||
path += "/";
|
||||
description = providedTemplate.getDescription();
|
||||
additionalProperties = providedTemplate.getAdditionalProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -120,5 +124,13 @@ public class TemplateImpl implements Template {
|
||||
public void setBundleContext(BundleContext bundleContext) {
|
||||
this.bundleContext = bundleContext;
|
||||
}
|
||||
|
||||
public Map<String, String> getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
|
||||
public void setAdditionalProperties(Map<String, String> additionalProperties) {
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public interface TemplateService {
|
||||
|
||||
public static final String TEMPLATE_PROVIDER_HEADER = "Entaxy-Template-Provider";
|
||||
|
||||
public static final String PROP_PREFIX = "template.";
|
||||
public static final String PROP_ID = "template.id";
|
||||
public static final String PROP_TYPE = "template.type";
|
||||
public static final String PROP_NAME = "template.name";
|
||||
|
@ -84,6 +84,11 @@ public class LegacyTemplateAdapter {
|
||||
public String getTemplateFullName() {
|
||||
return template.getTemplateFileName() + ".ftl";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAdditionalProperties() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@
|
||||
*/
|
||||
package ru.entaxy.base.generator.template.impl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
|
||||
import ru.entaxy.base.generator.template.Template;
|
||||
@ -32,6 +34,7 @@ public class ProvidedTemplate {
|
||||
protected String type;
|
||||
protected String path;
|
||||
protected String description;
|
||||
protected Map<String, String> additionalProperties = null;
|
||||
|
||||
public ServiceRegistration<Template> registration;
|
||||
|
||||
@ -47,6 +50,7 @@ public class ProvidedTemplate {
|
||||
this.type = templateMetadata.getType();
|
||||
this.path = templateMetadata.getPath();
|
||||
this.description = templateMetadata.getDescription();
|
||||
this.additionalProperties = templateMetadata.getAdditionalProperties();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@ -104,6 +108,14 @@ public class ProvidedTemplate {
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Map<String, String> getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
|
||||
public void setAdditionalProperties(Map<String, String> additionalProperties) {
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -24,9 +24,9 @@ import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
@ -93,29 +93,77 @@ public class TemplateBundleTrackerCustomizer implements BundleTrackerCustomizer<
|
||||
if (!isTemplateProvider)
|
||||
return null;
|
||||
|
||||
// Enumeration<String> entries = bundle.getEntryPaths(TemplateProvider.TEMPLATE_PATH + "/metadata.json");
|
||||
URL metadataUrl = bundle.getEntry(TemplateProvider.TEMPLATE_PATH + "/metadata.json");
|
||||
String metadata = new BufferedReader (
|
||||
new InputStreamReader(
|
||||
metadataUrl.openStream(), StandardCharsets.UTF_8))
|
||||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
Gson gson = builder.create();
|
||||
|
||||
JsonElement je = (new JsonParser()).parse(metadata);
|
||||
JsonObject root = je.getAsJsonObject();
|
||||
|
||||
JsonElement templatesElement = root.get("templates");
|
||||
if (templatesElement == null)
|
||||
return null;
|
||||
if (!templatesElement.isJsonArray())
|
||||
return null;
|
||||
JsonArray templates = templatesElement.getAsJsonArray();
|
||||
for (int i=0; i<templates.size(); i++) {
|
||||
TemplateMetadata meta = gson.fromJson(templates.get(i), TemplateMetadata.class);
|
||||
ProvidedTemplate providedTemplate = new ProvidedTemplate(meta);
|
||||
result.providedTemplates.add(providedTemplate);
|
||||
if (metadataUrl != null) {
|
||||
// descriptor is found
|
||||
|
||||
String metadata = new BufferedReader (
|
||||
new InputStreamReader(
|
||||
metadataUrl.openStream(), StandardCharsets.UTF_8))
|
||||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
Gson gson = builder.create();
|
||||
|
||||
JsonElement je = (new JsonParser()).parse(metadata);
|
||||
JsonObject root = je.getAsJsonObject();
|
||||
|
||||
JsonElement templatesElement = root.get("templates");
|
||||
if (templatesElement == null)
|
||||
return null;
|
||||
if (!templatesElement.isJsonArray())
|
||||
return null;
|
||||
JsonArray templates = templatesElement.getAsJsonArray();
|
||||
for (int i=0; i<templates.size(); i++) {
|
||||
TemplateMetadata meta = gson.fromJson(templates.get(i), TemplateMetadata.class);
|
||||
ProvidedTemplate providedTemplate = new ProvidedTemplate(meta);
|
||||
result.providedTemplates.add(providedTemplate);
|
||||
}
|
||||
|
||||
} else {
|
||||
// try to locate templates
|
||||
|
||||
log.debug("BEGIN :: Searching for templates in " + bundle.getBundleId());
|
||||
|
||||
Enumeration<URL> foundEntries = bundle.findEntries(TemplateProvider.TEMPLATE_PATH, "*.*", true);
|
||||
while (foundEntries.hasMoreElements()) {
|
||||
URL entry = foundEntries.nextElement();
|
||||
log.debug("FOUND :: " + entry.toString());
|
||||
if (entry.toString().endsWith("/")) {
|
||||
log.debug(":: .. is folder");
|
||||
continue;
|
||||
}
|
||||
String localPath = entry.toString();
|
||||
localPath = localPath.substring(localPath.indexOf(TemplateProvider.TEMPLATE_PATH) + TemplateProvider.TEMPLATE_PATH.length() + 1);
|
||||
String fullname = localPath.substring(localPath.lastIndexOf("/")+1);
|
||||
String path = localPath.lastIndexOf("/")>=0
|
||||
?localPath.substring(0, localPath.lastIndexOf("/"))
|
||||
:"";
|
||||
String fullPath = TemplateProvider.TEMPLATE_PATH + "/" + path;
|
||||
String fileName = fullname.substring(0, fullname.lastIndexOf("."));
|
||||
String fileType = fullname.substring(fullname.lastIndexOf(".")+1);
|
||||
String id = path.replace("/", ".")
|
||||
+ (path.isEmpty()?"":".")
|
||||
+ fileName;
|
||||
log.debug(":: localPath = " + localPath + "; fullName = " + fullname + "; fileName = " + fileName
|
||||
+ "; fileType = " + fileType + "; path = " + path);
|
||||
|
||||
TemplateMetadata meta = new TemplateMetadata();
|
||||
meta.setId(id);
|
||||
meta.setFilename(fileName);
|
||||
meta.setFullname(fullname);
|
||||
meta.setName(id);
|
||||
meta.setType(fileType);
|
||||
meta.setPath(fullPath);
|
||||
meta.setDescription("Found in bundle [" + bundle.getBundleId() + "] on path [" + localPath + "]");
|
||||
ProvidedTemplate providedTemplate = new ProvidedTemplate(meta);
|
||||
result.providedTemplates.add(providedTemplate);
|
||||
}
|
||||
|
||||
log.debug("END :: Searching for templates in " + bundle.getBundleId());
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -135,6 +183,9 @@ public class TemplateBundleTrackerCustomizer implements BundleTrackerCustomizer<
|
||||
props.put(TemplateService.PROP_NAME, provided.getName());
|
||||
props.put(TemplateService.PROP_TYPE, provided.getType());
|
||||
props.put(TemplateService.PROP_DESCRIPTION, provided.getDescription());
|
||||
if (provided.getAdditionalProperties() != null) {
|
||||
provided.getAdditionalProperties().forEach((k,v) -> {props.put(TemplateService.PROP_PREFIX + k, v);});
|
||||
}
|
||||
|
||||
ServiceRegistration<Template> registration =
|
||||
templateProvider.bundleContext.registerService(
|
||||
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
package ru.entaxy.base.generator.template.impl;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
@ -32,6 +33,7 @@ public class TemplateMetadata {
|
||||
protected String fullname;
|
||||
protected String path;
|
||||
protected String description = "";
|
||||
protected Map<String, String> additionalProperties;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
@ -93,5 +95,11 @@ public class TemplateMetadata {
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public Map<String, String> getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
public void setAdditionalProperties(Map<String, String> additionalProperties) {
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public interface Generated {
|
||||
|
||||
public static final String GENERATED_TYPE_BLUEPRINT = "blueprint";
|
||||
|
||||
public static final String GENERATED_TYPE_BLUEPRINT_NODE = "blueprint-node";
|
||||
public static final String GENERATED_TYPE_BLUEPRINT_FRAGMENT = "blueprint.fragment";
|
||||
|
||||
public static Generated create() {
|
||||
return new GeneratedImpl();
|
||||
|
@ -28,4 +28,5 @@ public interface Generator {
|
||||
|
||||
public String getGeneratorId();
|
||||
public Generated generate(Map<String, Object> properties) throws Exception;
|
||||
public boolean isGeneratable(Map<String, Object> properties) throws Exception;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>generator</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
|
||||
<artifactId>connecting</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -21,5 +21,6 @@
|
||||
<module>ftl-generator</module>
|
||||
<module>generator-factory</module>
|
||||
<module>common-templates-collection</module>
|
||||
<module>template-service-shell</module>
|
||||
</modules>
|
||||
</project>
|
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
@ -0,0 +1,50 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>generator</artifactId>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting.generator</groupId>
|
||||
<artifactId>template-service-shell</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>ENTAXY :: PLATFORM :: BASE :: TEMPLATES :: SHELL</name>
|
||||
<description>ENTAXY :: PLATFORM :: BASE :: TEMPLATES :: SHELL</description>
|
||||
|
||||
<properties>
|
||||
<bundle.osgi.remove.headers>NONE</bundle.osgi.remove.headers>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.karaf</groupId>
|
||||
<artifactId>org.apache.karaf.util</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.karaf.shell</groupId>
|
||||
<artifactId>org.apache.karaf.shell.core</artifactId>
|
||||
<version>${karaf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>
|
||||
ru.entaxy.esb.platform.runtime.base.connecting.generator
|
||||
</groupId>
|
||||
<artifactId>generator-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>
|
||||
ru.entaxy.esb.platform.runtime.base.connecting.generator
|
||||
</groupId>
|
||||
<artifactId>generator-factory</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
|
||||
<artifactId>base-support</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,88 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* template-service-test
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.base.generator.template.shell;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.karaf.shell.api.action.Action;
|
||||
import org.apache.karaf.shell.api.action.Argument;
|
||||
import org.apache.karaf.shell.api.action.Command;
|
||||
import org.apache.karaf.shell.api.action.lifecycle.Service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import ru.entaxy.base.generator.template.Template;
|
||||
import ru.entaxy.base.generator.template.TemplateAwareGenerator;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generator;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.factory.GeneratorFactory;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.base.support.JSONUtils;
|
||||
|
||||
@Service
|
||||
@Command(scope = "templates", name = "generate")
|
||||
public class Generate extends TemplateServiceSupport implements Action {
|
||||
|
||||
@Argument(index = 0, name = "template-id", required = true)
|
||||
String templateId;
|
||||
|
||||
@Argument(index = 1, name = "parameters", required = false)
|
||||
String params;
|
||||
|
||||
@Override
|
||||
public Object execute() throws Exception {
|
||||
Template t = templateService.getTemplateById(templateId);
|
||||
if (t == null) {
|
||||
System.out.println("Template [" + templateId + "] not found");
|
||||
return null;
|
||||
}
|
||||
TemplateAwareGenerator g = GeneratorFactory.createGenerator(t);
|
||||
if (g == null) {
|
||||
System.out.println("Generator for template [" + templateId + "] not found");
|
||||
return null;
|
||||
}
|
||||
Generated result = null;
|
||||
if (CommonUtils.isValid(params)) {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
Gson gson = builder.create();
|
||||
|
||||
JsonElement je = (new JsonParser()).parse(params);
|
||||
Map<String, Object> map = JSONUtils.element2map(je);
|
||||
|
||||
result = g.generate(t, map);
|
||||
} else {
|
||||
result = g.generate(t, new HashMap<>());
|
||||
}
|
||||
if (result == null) {
|
||||
System.out.println("Generated is empty, template: [" + templateId + "] not found");
|
||||
return null;
|
||||
} else {
|
||||
System.out.println("Generated: ");
|
||||
System.out.println("\ttype: " + result.getType());
|
||||
System.out.println("\tcontent: " + (result.getObject()==null?"null":"[==\n" + result.getObject().toString() + "\n==]"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* template-service-test
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.base.generator.template.shell;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.karaf.shell.api.action.Action;
|
||||
import org.apache.karaf.shell.api.action.Command;
|
||||
import org.apache.karaf.shell.api.action.lifecycle.Service;
|
||||
import org.apache.karaf.shell.support.table.ShellTable;
|
||||
|
||||
import ru.entaxy.base.generator.template.Template;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generator;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.factory.GeneratorFactory;
|
||||
|
||||
@Service
|
||||
@Command(scope = "templates", name = "list")
|
||||
public class ListTemplates extends TemplateServiceSupport implements Action {
|
||||
|
||||
@Override
|
||||
public Object execute() throws Exception {
|
||||
|
||||
ShellTable table = new ShellTable();
|
||||
table.column("id");
|
||||
table.column("File");
|
||||
table.column("Location");
|
||||
table.column("Generator");
|
||||
|
||||
for (Template t: templateService.getAllTemplates().stream().sorted(new Comparator<Template>() {
|
||||
|
||||
@Override
|
||||
public int compare(Template o1, Template o2) {
|
||||
return o1.getId().compareToIgnoreCase(o2.getId());
|
||||
}
|
||||
|
||||
}).collect(Collectors.toList()) ) {
|
||||
Generator g = (Generator)GeneratorFactory.createGenerator(t);
|
||||
table.addRow().addContent(
|
||||
t.getId(),
|
||||
t.getTemplateFullName(),
|
||||
t.getTemplateLocation()==null?"":t.getTemplateLocation().toString(),
|
||||
(g==null?"NOT FOUND":g.getGeneratorId())
|
||||
);
|
||||
}
|
||||
|
||||
table.print(System.out);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* template-service-test
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.base.generator.template.shell;
|
||||
|
||||
import org.apache.karaf.shell.api.action.lifecycle.Reference;
|
||||
|
||||
import ru.entaxy.base.generator.template.TemplateService;
|
||||
|
||||
public class TemplateServiceSupport {
|
||||
@Reference
|
||||
TemplateService templateService;
|
||||
|
||||
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime</groupId>
|
||||
<artifactId>base</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>producer</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
|
||||
<artifactId>connecting</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.connecting</groupId>
|
||||
<artifactId>producer</artifactId>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
Reference in New Issue
Block a user