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>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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user