ENTAXY-480 release version 1.8.3

This commit is contained in:
2023-08-03 04:44:09 +03:00
parent 603889d627
commit 5844a2e5cf
2546 changed files with 11242 additions and 207556 deletions

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -52,10 +52,16 @@ public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtend
String ID = "id";
String TYPE = "type";
String DISPLAY_NAME = "displayName";
String DESCRIPTION = "description";
String LABEL = "label";
String CATEGORY = "category";
String PARENT = "parent";
String REQUIRES = "requires";
String IS_ABSTRACT = "isAbstract";
String IS_DEPRECATED = "isDeprecated";
}
public static interface FIELDS {
@ -88,6 +94,8 @@ public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtend
String IS_REF = "isRef";
String ADD_TO_OUTPUT = "addToOutput";
}
String OBJECT_ID = "objectId";
@ -110,8 +118,78 @@ public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtend
}
}
public static interface DIRECTIVES {
String OVERRIDE = "@OVERRIDE";
String IMPORT = "@IMPORT";
String VARIANTS = "@VARIANTS";
String CALCULATED = "@CALCULATED";
String SCOPED = "@SCOPED";
String INTERNAL = "@INTERNAL";
static Set<String> getAllDirectives(){
return new HashSet<String>() {
private static final long serialVersionUID = 1L;
{
add(OVERRIDE);
add(IMPORT);
add(VARIANTS);
}};
}
public static enum OVERRIDE_MODE {
// leave parent value, no changes made
// parent value is 'final'
IGNORE("ignore"),
// child value is used
// parent value is ignored
REPLACE("replace"),
// use parent value
// with addition of new elements from child
APPEND("append"),
// use parent value updated from child
// with addition of new elements from child
UPDATE("update");
public String label;
private OVERRIDE_MODE(String label) {
this.label = label;
}
public static OVERRIDE_MODE valueOfLabel(String label) {
for (OVERRIDE_MODE e : values()) {
if (e.label.equalsIgnoreCase(label)) {
return e;
}
}
return null;
}
}
}
}
public static interface GENERATION {
public static interface ATTRIBUTES {
String OUTPUT = "generation.output";
String SCOPE = "generation.scope";
String FACTORY = "generation.factory";
}
}
static public enum SCOPE {
PUBLIC("public"),
@ -192,6 +270,10 @@ public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtend
return getType();
};
public boolean isAbstract();
public boolean isDeprecated();
public String getParent();
public List<OutputInfo> getOutputs();
public OutputInfo getDefaultOutput();
@ -199,6 +281,10 @@ public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtend
public List<FieldInfo> getFields();
public List<FieldInfo> getFields(String outputType);
public Map<String, Object> getTypeInfo();
public String getJsonConfiguration();
public Generated generate(Map<String, Object> parameters) throws EntaxyFactoryException ;
public Generated generate(String outputType, Map<String, Object> parameters) throws EntaxyFactoryException;

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,11 +31,25 @@ public interface EntaxyFactoryElements {
String getLabel();
default boolean hasLabel(String label) {
if ((label==null) || (label.trim().length() == 0) )
return false;
if (getLabel() == null)
return false;
String test = label.trim();
String[] labels = getLabel().split(",");
for (int i=0; i<labels.length; i++)
if (labels[i].trim().equalsIgnoreCase(test))
return true;
return false;
}
}
public interface EntaxyFactoryCommonElement extends EntaxyFactoryTypedElement {
String getId();
String getDisplayName();
String getDescription();
}

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,5 +20,33 @@
package ru.entaxy.platform.base.objects.factory;
public class EntaxyFactoryException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public EntaxyFactoryException() {
super();
}
public EntaxyFactoryException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
public EntaxyFactoryException(String message, Throwable cause) {
super(message, cause);
}
public EntaxyFactoryException(String message) {
super(message);
}
public EntaxyFactoryException(Throwable cause) {
super(cause);
}
}

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,10 +27,15 @@ public class FactoryElement extends AbstractElement<FactoryElement> {
protected String id;
protected String type;
protected String displayName;
protected String description;
protected String label;
protected String category;
protected String parent;
protected boolean isAbstract = false;
protected boolean isDeprecated = false;
public String getId() {
return id;
}
@ -61,5 +66,29 @@ public class FactoryElement extends AbstractElement<FactoryElement> {
public void setCategory(String category) {
this.category = category;
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
public boolean isAbstract() {
return isAbstract;
}
public void setAbstract(boolean isAbstract) {
this.isAbstract = isAbstract;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public boolean isDeprecated() {
return isDeprecated;
}
public void setDeprecated(boolean isDeprecated) {
this.isDeprecated = isDeprecated;
}
}

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.FIELDS;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.JSONUtils;
public class FieldElement implements EntaxyFactory.FieldInfo {
@ -39,11 +41,30 @@ public class FieldElement implements EntaxyFactory.FieldInfo {
boolean required = false;
Object defaultValue = "";
boolean conditional = false;
/*boolean conditional = false;*/
String condition = null;
boolean isRef = false;
public static FieldElement fromJson(String name, JsonElement element) {
Class<? extends FieldElement> feClass = FieldElement.class;
if (element.isJsonObject())
if (element.getAsJsonObject().has(FIELDS.ATTRIBUTES.IS_REF)) {
JsonElement val = element.getAsJsonObject().get(FIELDS.ATTRIBUTES.IS_REF);
if (val.isJsonPrimitive() && val.getAsJsonPrimitive().isBoolean())
if (val.getAsJsonPrimitive().getAsBoolean()) {
feClass = RefFieldElement.class;
}
}
FieldElement fe = (new Gson()).fromJson(element, feClass);
fe.setName(name);
fe.setJsonOrigin(element.isJsonObject()?element.getAsJsonObject():new JsonObject());
return fe;
}
public static FieldElement merge(FieldElement...elements) {
JsonObject result = new JsonObject();
@ -58,7 +79,7 @@ public class FieldElement implements EntaxyFactory.FieldInfo {
JSONUtils.mergeObjects(jsonObject, result);
}
FieldElement fe = (new Gson()).fromJson(result, FieldElement.class);
FieldElement fe = FieldElement.fromJson("merged", result);
fe.setJsonOrigin(result.deepCopy());
return fe;
}
@ -107,7 +128,7 @@ public class FieldElement implements EntaxyFactory.FieldInfo {
@Override
public boolean isConditional() {
return conditional;
return CommonUtils.isValid(this.condition);
}
@Override
@ -153,9 +174,9 @@ public class FieldElement implements EntaxyFactory.FieldInfo {
this.jsonOrigin = jsonOrigin;
}
public void setConditional(boolean conditional) {
/* public void setConditional(boolean conditional) {
this.conditional = conditional;
}
} */
public void setCondition(String condition) {
this.condition = condition;

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,7 @@
package ru.entaxy.platform.base.objects.factory.configuration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -41,7 +41,7 @@ public class FieldsElement extends AbstractElement<FieldsElement> {
public static final String ELEMENT_NAME = EntaxyFactory.CONFIGURATION.FIELDS_SECTION_NAME;
protected Map<String, FieldElement> fields = new HashMap<>();
protected Map<String, FieldElement> fields = new LinkedHashMap<>();
@Override
public FieldsElement fromJson(JsonElement jsonElement) {

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -60,9 +61,9 @@ public class OutputElement implements EntaxyFactory.OutputInfo {
protected FieldsElement fields = null;
protected Map<String, FieldElement> commonFields = new HashMap<>();
protected Map<String, FieldElement> commonFields = new LinkedHashMap<>();
protected Map<String, FieldElement> effectiveFields = new HashMap<>();
protected Map<String, FieldElement> effectiveFields = new LinkedHashMap<>();
protected boolean isEffectiveCalculated = false;
@ -122,6 +123,8 @@ public class OutputElement implements EntaxyFactory.OutputInfo {
} else {
// use only locally mentioned fields
// except common fields with "addToOutput" set to current output type or "*"
ownedFields = fields.getFieldsMap();
log.debug("->" + getType() + " ownedFields: " + fields.getFieldsMap().size());
@ -131,6 +134,23 @@ public class OutputElement implements EntaxyFactory.OutputInfo {
FieldElement fe = FieldElement.merge(entry.getValue(), ownedFields.get(entry.getKey()));
fe.setName(entry.getKey());
this.effectiveFields.put(entry.getKey(), fe);
} else {
if (entry.getValue().getJsonOrigin().has(EntaxyFactory.CONFIGURATION.FIELDS.ATTRIBUTES.ADD_TO_OUTPUT)) {
String value = entry.getValue().getJsonOrigin()
.get(EntaxyFactory.CONFIGURATION.FIELDS.ATTRIBUTES.ADD_TO_OUTPUT)
.getAsString();
String[] values = value.split(",");
boolean addField = false;
for (int i=0; i<values.length; i++)
if ("*".equals(values[i].trim()) || this.type.equals(values[i].trim())) {
addField = true;
break;
}
if (addField)
this.effectiveFields.put(entry.getKey(), entry.getValue());
}
}
}
}

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@
package ru.entaxy.platform.base.objects.factory.impl;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -39,6 +40,7 @@ import com.google.gson.JsonParser;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryException;
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryUtils;
import ru.entaxy.platform.base.objects.factory.configuration.AbstractElement;
import ru.entaxy.platform.base.objects.factory.configuration.FactoryElement;
import ru.entaxy.platform.base.objects.factory.configuration.FieldsElement;
@ -57,13 +59,21 @@ public class DefaultFactory implements EntaxyFactory {
protected String factoryId = "";
protected String factoryType = "";
protected String description;
protected String displayName;
protected String label;
protected String category;
protected String parent;
protected boolean isAbstract;
protected boolean isDeprecated;
protected FieldsElement fields = null;
protected OutputsElement outputs = new OutputsElement();
@ -72,6 +82,8 @@ public class DefaultFactory implements EntaxyFactory {
protected GenerationHelper helper = null;
protected JsonObject originJson;
public DefaultFactory() {
super();
elementClasses.put(FactoryElement.ELEMENT_NAME, FactoryElement.class);
@ -95,11 +107,14 @@ public class DefaultFactory implements EntaxyFactory {
log.debug("CONFIGURE WITH: " + configuration);
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
JsonElement je = (new JsonParser()).parse(configuration);
JsonObject root = je.getAsJsonObject();
JsonObject root = je.getAsJsonObject();
this.configure(root);
}
public void configure(JsonObject root) {
this.originJson = root.deepCopy();
Set<Entry<String, JsonElement>> elementSet = root.entrySet();
for (Entry<String, JsonElement> entry: elementSet) {
@ -132,7 +147,11 @@ public class DefaultFactory implements EntaxyFactory {
this.factoryType = fe.getType();
this.category = fe.getCategory();
this.label = fe.getLabel();
this.displayName = fe.getDisplayName();
this.description = fe.getDescription();
this.parent = fe.getParent();
this.isAbstract = fe.isAbstract();
this.isDeprecated = fe.isDeprecated();
} else if (object instanceof OutputsElement) {
log.debug("POSTPROCESS :: OutputsElement");
this.outputs = (OutputsElement)object;
@ -175,6 +194,11 @@ public class DefaultFactory implements EntaxyFactory {
return this.factoryType;
}
@Override
public String getDisplayName() {
return displayName;
}
@Override
public String getDescription() {
return description;
@ -190,6 +214,34 @@ public class DefaultFactory implements EntaxyFactory {
return category;
}
@Override
public String getParent() {
return parent;
}
@Override
public boolean isAbstract() {
return isAbstract;
}
@Override
public boolean isDeprecated() {
return isDeprecated;
}
@Override
public Map<String, Object> getTypeInfo() {
if (factoryData.containsKey(getType()))
return (Map<String, Object>)factoryData.get(getType());
return Collections.emptyMap();
}
@Override
public String getJsonConfiguration() {
//JsonElement je = (new Gson()).toJsonTree(this.factoryData);
return EntaxyFactoryUtils.getEffectiveJson(this);
}
@Override
public Generated generate(Map<String, Object> parameters) throws EntaxyFactoryException {
return generate(this.outputs.getDefaultOutputType(), parameters);
@ -207,13 +259,15 @@ public class DefaultFactory implements EntaxyFactory {
log.debug("Generating for: output type [{}], scope [{}]", outputType, scope);
if (!this.outputs.hasOutput(outputType)) {
log.debug("Unknown output: {}", outputType);
log.debug("Factory: {}. Unknown output: {}", this.getId(), outputType);
throw new EntaxyFactoryException();
}
OutputElement oe = this.outputs.getOutput(outputType);
if (!oe.isScopeSupported(scope)) {
log.error("Scope not supported: {}; supported scopes: [{}]"
log.error("Factory: {}, output: {}. Scope not supported: {}; supported scopes: [{}]"
, this.getId()
, oe.getType()
, scope
, oe.getSupportedScopes().stream().map(s -> s.label).collect(Collectors.joining(",")));
throw new EntaxyFactoryException();

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@
*/
package ru.entaxy.platform.base.objects.factory.impl;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -41,6 +42,7 @@ import ru.entaxy.esb.platform.runtime.base.connecting.generator.factory.Generato
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.OutputInfo;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.SCOPE;
import ru.entaxy.platform.base.support.CommonUtils;
@Component(immediate = true, service = {GenerationHelper.class})
public class GenerationHelper {
@ -50,10 +52,13 @@ public class GenerationHelper {
@Reference(cardinality = ReferenceCardinality.MANDATORY, collectionType = CollectionType.SERVICE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
protected volatile TemplateService templateService;
@Reference(cardinality = ReferenceCardinality.MANDATORY)
FactoryRegistry factoryRegistry;
public Generated generateForFactory(EntaxyFactory factory, String outputType, SCOPE scope, Map<String, Object> parameters) throws Exception {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "]");
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: PARAMETERS \n"
log.debug("GENERATING for factory [" + factory.getId() + "]");
log.debug("GENERATING for factory [" + factory.getId() + "] :: PARAMETERS \n"
+ parameters.entrySet().stream().map(e -> e.getKey() + ":" + (null==e.getValue()?"null":e.getValue()))
.collect(Collectors.toList())
.stream().collect(Collectors.joining(", "))
@ -63,39 +68,63 @@ public class GenerationHelper {
if (outputInfo == null) {
// @TODO throw Exception
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: output [{}] not found", outputType);
log.debug("GENERATING for factory [" + factory.getId() + "] :: output [{}] not found", outputType);
return null;
}
if (!outputInfo.getScopes().contains(scope.label)) {
// @TODO throw Exception
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: scope [{}] not supported", scope.label);
log.debug("GENERATING for factory [" + factory.getId() + "] :: scope [{}] not supported", scope.label);
return null;
}
Map<String, Object> generationProperties = new HashMap<>();
generationProperties.put(EntaxyFactory.GENERATION.ATTRIBUTES.OUTPUT, outputType);
generationProperties.put(EntaxyFactory.GENERATION.ATTRIBUTES.SCOPE, scope.label);
generationProperties.put(EntaxyFactory.GENERATION.ATTRIBUTES.FACTORY, factory.getId());
// try to generate via GeneratorFactory
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: TRY via GeneratorFactory");
Generator g = GeneratorFactory.createGenerator(outputInfo.getGenerator(), outputInfo.getConfig());
if (g.isGeneratable(parameters)) {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: generating");
return g.generate(parameters);
log.debug("GENERATING for factory [" + factory.getId() + "] :: TRY via GeneratorFactory");
Map<String, Object> generatorProperties = new HashMap<>(outputInfo.getConfig());
generatorProperties.putAll(generationProperties);
Generator g = GeneratorFactory.createGenerator(outputInfo.getGenerator(), generatorProperties);
Map<String, Object> generationParameters = new HashMap<>(parameters);
generationParameters.putAll(generationProperties);
if (g.isGeneratable(generationParameters)) {
log.debug("GENERATING for factory [" + factory.getId() + "] :: generating");
return g.generate(generationParameters);
} else {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: NOT generatable");
log.debug("GENERATING for factory [" + factory.getId() + "] :: NOT generatable");
}
// try to generate via TemplateService
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: TRY via TemplateService");
log.debug("GENERATING for factory [" + factory.getId() + "] :: TRY via TemplateService");
List<String> candidates = new LinkedList<>();
candidates.add(factory.getFactoryId() + "." + outputType + "." + scope.label);
candidates.add(factory.getFactoryId() + "." + outputType);
candidates.add(factory.getId() + "." + outputType + "." + scope.label);
candidates.add(factory.getId() + "." + outputType);
if (outputInfo.isDefault()) {
candidates.add(factory.getFactoryId() + ".default." + scope.label);
candidates.add(factory.getFactoryId() + ".default");
candidates.add(factory.getFactoryId() + "." + scope.label);
candidates.add(factory.getFactoryId());
candidates.add(factory.getId() + ".default." + scope.label);
candidates.add(factory.getId() + ".default");
candidates.add(factory.getId() + "." + scope.label);
candidates.add(factory.getId());
}
String parent = factory.getParent();
while (CommonUtils.isValid(parent)) {
candidates.add(parent + "." + outputType + "." + scope.label);
candidates.add(parent + "." + outputType);
String newParent = factoryRegistry.getParentFactory(parent);
// exclude cyclic references
if (parent.equalsIgnoreCase(newParent))
break;
parent = newParent;
}
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: CANDIDATES : ["
log.debug("GENERATING for factory [" + factory.getId() + "] :: CANDIDATES : ["
+ candidates.stream().collect(Collectors.joining(";"))
+ "]"
);
@ -103,12 +132,12 @@ public class GenerationHelper {
for (String candidate: candidates) {
Template t = templateService.getTemplateById(candidate);
if (t != null) {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: FOUND TEMPLATE : ["
log.debug("GENERATING for factory [" + factory.getId() + "] :: FOUND TEMPLATE : ["
+ candidate + "]");
Generated result = GeneratorFactory.createGenerator(t).generate(t, parameters);
return result;
} else {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: NOT FOUND TEMPLATE : ["
log.debug("GENERATING for factory [" + factory.getId() + "] :: NOT FOUND TEMPLATE : ["
+ candidate + "]");
}
}

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,7 +27,10 @@ import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.JsonObject;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.support.CommonUtils;
public class TrackedFactory {
@ -77,6 +80,11 @@ public class TrackedFactory {
if (this.serviceRegistration != null)
try {
this.serviceRegistration.unregister();
} catch (IllegalStateException e) {
// skip exception typical for bundle refreshing process
if (CommonUtils.isValid(e.getMessage()) && e.getMessage().contains("Service already unregistered"))
return;
log.warn("TrackedFactory [" + getId() + "]", e);
} catch (Exception e) {
log.warn("TrackedFactory [" + getId() + "]", e);
}

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,7 @@ import org.osgi.framework.BundleEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.platform.base.support.JSONUtils;
import ru.entaxy.platform.base.support.osgi.tracker.UniformBundleTrackerCustomizer;
public class TrackedFactoryCustomizer extends UniformBundleTrackerCustomizer<List<TrackedFactory>> {
@ -60,11 +61,13 @@ public class TrackedFactoryCustomizer extends UniformBundleTrackerCustomizer<Lis
log.debug("Found id: " + id);
try {
String config = new BufferedReader (
/* String config = new BufferedReader (
new InputStreamReader(
entry.openStream(), StandardCharsets.UTF_8))
.lines()
.collect(Collectors.joining("\n"));
*/
String config = JSONUtils.getJsonRootObjectString(entry);
TrackedFactory tf = new TrackedFactory();
tf.setId(id);
tf.setBundle(bundle);

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,14 +24,11 @@ import java.util.Hashtable;
import java.util.List;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.base.generator.template.TemplateService;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.impl.DefaultFactory;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.osgi.tracker.BundleTrackerCustomizerListener;
public class TrackedFactoryCustomizerListener implements BundleTrackerCustomizerListener<List<TrackedFactory>> {

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 EmDev LLC
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,6 +27,8 @@ import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.util.tracker.BundleTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -43,6 +45,9 @@ public class TrackerManager {
protected BundleTracker<List<TrackedFactory>> factoryTracker;
@Reference (cardinality = ReferenceCardinality.MANDATORY)
TrackedFactoryManager factoryManager;
@Activate
public void activate(ComponentContext componentContext) {
this.bundleContext = componentContext.getBundleContext();
@ -54,7 +59,8 @@ public class TrackerManager {
)
.customizer(
(new TrackedFactoryCustomizer())
.listener(new TrackedFactoryCustomizerListener(bundleContext))
// .listener(new TrackedFactoryCustomizerListener(bundleContext))
.listener(factoryManager)
)
.bundleState(Bundle.ACTIVE | Bundle.INSTALLED | Bundle.RESOLVED)
.get();