release version 1.10.0
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
|
||||
<artifactId>objects-base</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<version>1.10.0</version>
|
||||
</parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base.objects-base</groupId>
|
||||
<artifactId>object-factory</artifactId>
|
||||
@ -53,6 +53,12 @@
|
||||
<artifactId>generator-factory</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.platform</groupId>
|
||||
<artifactId>search-service</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -27,326 +27,432 @@ package ru.entaxy.platform.base.objects.factory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
|
||||
public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtendedElement {
|
||||
|
||||
/*
|
||||
* public constants, enums etc
|
||||
*/
|
||||
|
||||
public static interface SERVICE {
|
||||
/*
|
||||
* public constants, enums etc
|
||||
*/
|
||||
|
||||
String PROP_ID = "factory.id";
|
||||
String PROP_TYPE = "factory.type";
|
||||
String PROP_ORIGIN_BUNDLE = "factory.origin.bundle";
|
||||
|
||||
}
|
||||
public static interface SERVICE {
|
||||
|
||||
public static interface CONFIGURATION {
|
||||
String PROP_ID = "factory.id";
|
||||
String PROP_TYPE = "factory.type";
|
||||
String PROP_ORIGIN_BUNDLE = "factory.origin.bundle";
|
||||
|
||||
String FACTORY_SECTION_NAME = "factory";
|
||||
String FIELDS_SECTION_NAME = "fields";
|
||||
String OUTPUTS_SECTION_NAME = "outputs";
|
||||
|
||||
public static interface FACTORY {
|
||||
|
||||
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 {
|
||||
|
||||
public static interface REGULAR_TYPES {
|
||||
|
||||
String STRING = "String";
|
||||
String BOOLEAN = "Boolean";
|
||||
String LONG = "Long";
|
||||
String DOUBLE = "Double";
|
||||
|
||||
public static Set<String> asSet() {
|
||||
return new HashSet<>() {{
|
||||
add(STRING);
|
||||
add(BOOLEAN);
|
||||
add(DOUBLE);
|
||||
add(LONG);
|
||||
}};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static interface ATTRIBUTES {
|
||||
|
||||
String FIELD_TYPE = "type";
|
||||
String DEFAULT_VALUE = "defaultValue";
|
||||
|
||||
String REQUIRED = "required";
|
||||
String IMMUTABLE = "immutable";
|
||||
|
||||
String IS_REF = "isRef";
|
||||
|
||||
String ADD_TO_OUTPUT = "addToOutput";
|
||||
|
||||
}
|
||||
|
||||
String OBJECT_ID = "objectId";
|
||||
|
||||
}
|
||||
|
||||
public static interface OUTPUTS {
|
||||
}
|
||||
|
||||
String OUTPUT_TYPE_INIT = "init";
|
||||
String OUTPUT_TYPE_REF = "ref";
|
||||
|
||||
public static interface ATTRIBUTES {
|
||||
|
||||
String IS_DEFAULT = "isDefault";
|
||||
String CONFIG = "config";
|
||||
String GENERATOR = "generator";
|
||||
String FIELDS = "fields";
|
||||
String SCOPES = "scopes";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static interface DIRECTIVES {
|
||||
|
||||
String OVERRIDE = "@OVERRIDE";
|
||||
String INHERIT = "@INHERIT";
|
||||
String IMPORT = "@IMPORT";
|
||||
String VARIANTS = "@VARIANTS";
|
||||
String CALCULATED = "@CALCULATED";
|
||||
String SCOPED = "@SCOPED";
|
||||
String INTERNAL = "@INTERNAL";
|
||||
String LOCALS = "@LOCALS";
|
||||
public static interface CONFIGURATION {
|
||||
|
||||
static Set<String> getAllDirectives(){
|
||||
return new HashSet<String>() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
String FACTORY_SECTION_NAME = "factory";
|
||||
String FIELDS_SECTION_NAME = "fields";
|
||||
String OUTPUTS_SECTION_NAME = "outputs";
|
||||
|
||||
{
|
||||
add(OVERRIDE);
|
||||
add(IMPORT);
|
||||
add(VARIANTS);
|
||||
}};
|
||||
}
|
||||
public static interface FACTORY {
|
||||
|
||||
static Set<String> designDirectives = new HashSet<>(Arrays.asList(
|
||||
new String[]{
|
||||
OVERRIDE, INHERIT, IMPORT, VARIANTS, SCOPED}
|
||||
));
|
||||
|
||||
static Set<String> getDesingDirectives(){
|
||||
return designDirectives;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
String ID = "id";
|
||||
String TYPE = "type";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mode for array data inheritance
|
||||
* @author Serge
|
||||
*
|
||||
*/
|
||||
public static enum INHERIT_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"),
|
||||
String SHORT_NAME = "shortName";
|
||||
String DISPLAY_NAME = "displayName";
|
||||
String DESCRIPTION = "description";
|
||||
String LABEL = "label";
|
||||
String CATEGORY = "category";
|
||||
|
||||
// use parent value
|
||||
// with addition of new elements from child in the beginning
|
||||
PREPEND("prepend");
|
||||
|
||||
public String label;
|
||||
String PARENT = "parent";
|
||||
String REQUIRES = "requires";
|
||||
|
||||
private INHERIT_MODE(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static INHERIT_MODE valueOfLabel(String label) {
|
||||
for (INHERIT_MODE e : values()) {
|
||||
if (e.label.equalsIgnoreCase(label)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
String IS_ABSTRACT = "isAbstract";
|
||||
String IS_DEPRECATED = "isDeprecated";
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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"),
|
||||
PROTECTED("protected"),
|
||||
PRIVATE("private");
|
||||
|
||||
public String label;
|
||||
String IS_INTERNAL = "isInternal";
|
||||
}
|
||||
|
||||
private SCOPE(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static SCOPE valueOfLabel(String label) {
|
||||
for (SCOPE e : values()) {
|
||||
if (e.label.equals(label)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public SCOPE DEFAULT_SCOPE = SCOPE.PUBLIC;
|
||||
|
||||
/*
|
||||
* inner structure elements
|
||||
*/
|
||||
|
||||
public static interface OutputInfo {
|
||||
|
||||
public String getType();
|
||||
public String getGenerator();
|
||||
public List<String> getScopes();
|
||||
public Map<String, Object> getConfig();
|
||||
public List<FieldInfo> getFields();
|
||||
public boolean isDefault();
|
||||
|
||||
}
|
||||
public static interface FIELDS {
|
||||
|
||||
public static interface FieldInfo {
|
||||
|
||||
public String getName();
|
||||
public String getType();
|
||||
public String getDisplayName();
|
||||
public String getDescription();
|
||||
public static interface REGULAR_TYPES {
|
||||
|
||||
public boolean isImmutable();
|
||||
public boolean isRequired();
|
||||
public Object getDefaultValue();
|
||||
String STRING = "String";
|
||||
String BOOLEAN = "Boolean";
|
||||
String LONG = "Long";
|
||||
String DOUBLE = "Double";
|
||||
|
||||
public boolean isConditional();
|
||||
public String getCondition();
|
||||
|
||||
public boolean isRef();
|
||||
public JsonObject getJsonOrigin();
|
||||
|
||||
}
|
||||
public static Set<String> asSet() {
|
||||
return new HashSet<>() {
|
||||
{
|
||||
add(STRING);
|
||||
add(BOOLEAN);
|
||||
add(DOUBLE);
|
||||
add(LONG);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static interface RefFieldInfo extends FieldInfo {
|
||||
|
||||
public boolean isBackRef();
|
||||
public boolean isRefByValueOnly();
|
||||
|
||||
public String getRefField();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Factory itself
|
||||
*/
|
||||
}
|
||||
|
||||
@Deprecated()
|
||||
public default String getFactoryId() {
|
||||
return getId();
|
||||
};
|
||||
@Deprecated
|
||||
public default String getFactoryType() {
|
||||
return getType();
|
||||
};
|
||||
|
||||
public boolean isAbstract();
|
||||
public boolean isDeprecated();
|
||||
|
||||
public String getParent();
|
||||
|
||||
public List<OutputInfo> getOutputs();
|
||||
public OutputInfo getDefaultOutput();
|
||||
public OutputInfo getOutputByType(String outputType);
|
||||
|
||||
public List<FieldInfo> getFields();
|
||||
public List<FieldInfo> getFields(String outputType);
|
||||
public static interface ATTRIBUTES {
|
||||
|
||||
String FIELD_TYPE = "type";
|
||||
|
||||
String FIELD_DISPLAY_NAME = "displayName";
|
||||
String FIELD_DESCRIPTION = "description";
|
||||
|
||||
String DEFAULT_VALUE = "defaultValue";
|
||||
|
||||
String REQUIRED = "required";
|
||||
String IMMUTABLE = "immutable";
|
||||
|
||||
String IS_REF = "isRef";
|
||||
|
||||
String ADD_TO_OUTPUT = "addToOutput";
|
||||
|
||||
}
|
||||
|
||||
String OBJECT_ID = "objectId";
|
||||
|
||||
}
|
||||
|
||||
public static interface OUTPUTS {
|
||||
|
||||
String OUTPUT_TYPE_INIT = "init";
|
||||
String OUTPUT_TYPE_REF = "ref";
|
||||
|
||||
public static interface ATTRIBUTES {
|
||||
|
||||
String IS_DEFAULT = "isDefault";
|
||||
String CONFIG = "config";
|
||||
String GENERATOR = "generator";
|
||||
String FIELDS = "fields";
|
||||
String SCOPES = "scopes";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static interface DIRECTIVES {
|
||||
|
||||
String OVERRIDE = "@OVERRIDE";
|
||||
String INHERIT = "@INHERIT";
|
||||
String IMPORT = "@IMPORT";
|
||||
String VARIANTS = "@VARIANTS";
|
||||
String CALCULATED = "@CALCULATED";
|
||||
String SCOPED = "@SCOPED";
|
||||
String INTERNAL = "@INTERNAL";
|
||||
String NO_LOOKUP = "@NO_LOOKUP";
|
||||
String LOCALS = "@LOCALS";
|
||||
|
||||
static Set<String> getAllDirectives() {
|
||||
return new HashSet<String>() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
add(OVERRIDE);
|
||||
add(IMPORT);
|
||||
add(VARIANTS);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static Set<String> designDirectives = new HashSet<>(Arrays.asList(
|
||||
new String[] {
|
||||
OVERRIDE, INHERIT, IMPORT, VARIANTS, SCOPED, LOCALS}));
|
||||
|
||||
static Set<String> getDesignDirectives() {
|
||||
return designDirectives;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mode for array data inheritance
|
||||
*
|
||||
* @author Serge
|
||||
*
|
||||
*/
|
||||
public static enum INHERIT_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
|
||||
// with addition of new elements from child in the beginning
|
||||
PREPEND("prepend");
|
||||
|
||||
public String label;
|
||||
|
||||
private INHERIT_MODE(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static INHERIT_MODE valueOfLabel(String label) {
|
||||
for (INHERIT_MODE e : values()) {
|
||||
if (e.label.equalsIgnoreCase(label)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static interface SEARCH {
|
||||
|
||||
String ATTR_ID = CONFIGURATION.FACTORY.ID;
|
||||
String ATTR_TYPE = CONFIGURATION.FACTORY.TYPE;
|
||||
String ATTR_PARENT = CONFIGURATION.FACTORY.PARENT;
|
||||
|
||||
String ATTR_SHORT_NAME = CONFIGURATION.FACTORY.SHORT_NAME;
|
||||
String ATTR_DISPLAY_NAME = CONFIGURATION.FACTORY.DISPLAY_NAME;
|
||||
String ATTR_DESCRIPTION = CONFIGURATION.FACTORY.DESCRIPTION;
|
||||
String ATTR_LABEL = CONFIGURATION.FACTORY.LABEL;
|
||||
String ATTR_CATEGORY = CONFIGURATION.FACTORY.CATEGORY;
|
||||
|
||||
String ATTR_REQUIRES = CONFIGURATION.FACTORY.REQUIRES;
|
||||
|
||||
String ATTR_IS_ABSTRACT = CONFIGURATION.FACTORY.IS_ABSTRACT;
|
||||
String ATTR_IS_DEPRECATED = CONFIGURATION.FACTORY.IS_DEPRECATED;
|
||||
|
||||
String ATTR_IS_INTERNAL = CONFIGURATION.FACTORY.IS_INTERNAL;
|
||||
|
||||
String ATTR_TYPEINFO_PREFIX = "typeinfo.";
|
||||
String ATTR_TYPEINFO = ATTR_TYPEINFO_PREFIX + "*";
|
||||
|
||||
List<String> STANDARD_ATTRIBUTES_LIST = Arrays.asList(new String[] {
|
||||
ATTR_ID,
|
||||
ATTR_TYPE,
|
||||
ATTR_PARENT,
|
||||
|
||||
ATTR_SHORT_NAME,
|
||||
ATTR_DISPLAY_NAME,
|
||||
ATTR_DESCRIPTION,
|
||||
ATTR_LABEL,
|
||||
ATTR_CATEGORY,
|
||||
|
||||
ATTR_REQUIRES,
|
||||
|
||||
ATTR_IS_ABSTRACT,
|
||||
ATTR_IS_DEPRECATED,
|
||||
ATTR_IS_INTERNAL,
|
||||
|
||||
ATTR_TYPEINFO
|
||||
|
||||
});
|
||||
|
||||
Map<String, String> STANDARD_ATTRIBUTES = MapUtils.putAll(new LinkedHashMap<>(), new String[][] {
|
||||
{ATTR_ID, "Factory Id"},
|
||||
{ATTR_TYPE, "Factory type"},
|
||||
{ATTR_PARENT, "Parent factory Id"},
|
||||
|
||||
{ATTR_SHORT_NAME, "Factory short name"},
|
||||
{ATTR_DISPLAY_NAME, "Factory display name"},
|
||||
{ATTR_DESCRIPTION, "Descrption"},
|
||||
{ATTR_LABEL, "Label"},
|
||||
{ATTR_CATEGORY, "Category"},
|
||||
|
||||
{ATTR_REQUIRES, "Requirements"},
|
||||
|
||||
{ATTR_IS_ABSTRACT, "Is factory abstract"},
|
||||
{ATTR_IS_DEPRECATED, "Is factory deprecated"},
|
||||
{ATTR_IS_INTERNAL, "Is factory internal"},
|
||||
|
||||
{ATTR_TYPEINFO, "Specific type information"}
|
||||
});
|
||||
}
|
||||
|
||||
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"),
|
||||
PROTECTED("protected"),
|
||||
PRIVATE("private");
|
||||
|
||||
public String label;
|
||||
|
||||
private SCOPE(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static SCOPE valueOfLabel(String label) {
|
||||
for (SCOPE e : values()) {
|
||||
if (e.label.equals(label)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public SCOPE DEFAULT_SCOPE = SCOPE.PUBLIC;
|
||||
|
||||
/*
|
||||
* inner structure elements
|
||||
*/
|
||||
|
||||
public static interface OutputInfo {
|
||||
|
||||
public String getType();
|
||||
|
||||
public String getGenerator();
|
||||
|
||||
public List<String> getScopes();
|
||||
|
||||
public Map<String, Object> getConfig();
|
||||
|
||||
public List<FieldInfo> getFields();
|
||||
|
||||
public boolean isDefault();
|
||||
|
||||
}
|
||||
|
||||
public static interface FieldInfo {
|
||||
|
||||
public String getName();
|
||||
|
||||
public String getType();
|
||||
|
||||
public String getDisplayName();
|
||||
|
||||
public String getDescription();
|
||||
|
||||
public boolean isImmutable();
|
||||
|
||||
public boolean isRequired();
|
||||
|
||||
public Object getDefaultValue();
|
||||
|
||||
public boolean isConditional();
|
||||
|
||||
public String getCondition();
|
||||
|
||||
public boolean isRef();
|
||||
|
||||
public JsonObject getJsonOrigin();
|
||||
|
||||
}
|
||||
|
||||
public static interface RefFieldInfo extends FieldInfo {
|
||||
|
||||
public boolean isBackRef();
|
||||
|
||||
public boolean isRefByValueOnly();
|
||||
|
||||
public String getRefField();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Factory itself
|
||||
*/
|
||||
|
||||
@Deprecated()
|
||||
public default String getFactoryId() {
|
||||
return getId();
|
||||
};
|
||||
|
||||
@Deprecated
|
||||
public default String getFactoryType() {
|
||||
return getType();
|
||||
};
|
||||
|
||||
public String getShortName();
|
||||
|
||||
public boolean isAbstract();
|
||||
|
||||
public boolean isInternal();
|
||||
|
||||
public boolean isDeprecated();
|
||||
|
||||
public String getParent();
|
||||
|
||||
public List<OutputInfo> getOutputs();
|
||||
|
||||
public OutputInfo getDefaultOutput();
|
||||
|
||||
public OutputInfo getOutputByType(String outputType);
|
||||
|
||||
public List<FieldInfo> getFields();
|
||||
|
||||
public List<FieldInfo> getFields(String outputType);
|
||||
|
||||
public Map<String, Object> getTypeInfo();
|
||||
|
||||
public String getJsonConfiguration();
|
||||
|
||||
public String getJsonOrigin();
|
||||
|
||||
public Generated generate(Map<String, Object> parameters) throws EntaxyFactoryException;
|
||||
|
||||
public Generated generate(String outputType, Map<String, Object> parameters) throws EntaxyFactoryException;
|
||||
|
||||
public Generated generate(String outputType, String scope, Map<String, Object> parameters)
|
||||
throws EntaxyFactoryException;
|
||||
|
||||
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;
|
||||
public Generated generate(String outputType, String scope, Map<String, Object> parameters) throws EntaxyFactoryException;
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -27,6 +27,7 @@ package ru.entaxy.platform.base.objects.factory;
|
||||
|
||||
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;
|
||||
@ -51,429 +52,492 @@ import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.base.support.JSONUtils;
|
||||
|
||||
public class EntaxyFactoryUtils {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(EntaxyFactoryUtils.class);
|
||||
|
||||
public static final String PROP_HIERARCHY = "hierarchy";
|
||||
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
public static String getEffectiveJson(EntaxyFactory factory) {
|
||||
JsonObject result = new JsonObject();
|
||||
|
||||
// factory
|
||||
JsonObject factoryData = new JsonObject();
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.ID, factory.getId());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.TYPE, factory.getType());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.CATEGORY, factory.getCategory());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.LABEL, factory.getLabel());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.DESCRIPTION, factory.getDescription());
|
||||
result.add(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME, factoryData);
|
||||
|
||||
// typed data
|
||||
String type = factory.getType();
|
||||
JsonElement typeData = gson.toJsonTree(factory.getTypeInfo());
|
||||
result.add(type, typeData);
|
||||
|
||||
// fields
|
||||
JsonObject fieldsData = new JsonObject();
|
||||
for (FieldInfo fi: factory.getFields()) {
|
||||
fieldsData.add(fi.getName(), fi.getJsonOrigin());
|
||||
}
|
||||
result.add(EntaxyFactory.CONFIGURATION.FIELDS_SECTION_NAME, fieldsData);
|
||||
|
||||
// outputs
|
||||
JsonObject outputsData = new JsonObject();
|
||||
for (OutputInfo oi: factory.getOutputs()) {
|
||||
JsonObject outputData = new JsonObject();
|
||||
outputData.addProperty(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.IS_DEFAULT, oi.isDefault());
|
||||
outputData.addProperty(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.GENERATOR, oi.getGenerator());
|
||||
outputData.add(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.SCOPES
|
||||
, gson.toJsonTree(oi.getScopes()));
|
||||
if (oi.getConfig() != null)
|
||||
outputData.add(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.CONFIG
|
||||
, gson.toJsonTree(oi.getConfig()));
|
||||
JsonObject outputFields = new JsonObject();
|
||||
for (FieldInfo fi: oi.getFields()) {
|
||||
outputFields.add(fi.getName(), fi.getJsonOrigin());
|
||||
}
|
||||
outputData.add(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.FIELDS, outputFields);
|
||||
outputsData.add(oi.getType(), outputData);
|
||||
}
|
||||
result.add(EntaxyFactory.CONFIGURATION.OUTPUTS_SECTION_NAME, outputsData);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static JsonObject cleanJson(JsonObject origin) {
|
||||
JsonObject result = origin.deepCopy();
|
||||
|
||||
cleanObject(result, EntaxyFactory.CONFIGURATION.DIRECTIVES.getAllDirectives());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void cleanObject(JsonObject origin, Set<String> toRemove) {
|
||||
for (String name: toRemove)
|
||||
origin.remove(name);
|
||||
for (Entry<String, JsonElement> entry: origin.entrySet())
|
||||
if (entry.getValue().isJsonObject())
|
||||
cleanObject(entry.getValue().getAsJsonObject(), toRemove);
|
||||
}
|
||||
|
||||
public static interface FactoryConfigurationStorage {
|
||||
JsonObject getConfiguration(String factoryId);
|
||||
}
|
||||
|
||||
public static JsonObject calculateEffectiveJson(JsonObject origin, FactoryConfigurationStorage storage) {
|
||||
JsonObject originCopy = origin.deepCopy();
|
||||
JsonObject result = originCopy;
|
||||
JsonObject error = new JsonObject();
|
||||
JsonObject errorData = new JsonObject();
|
||||
JsonArray errorReqs = new JsonArray();
|
||||
|
||||
error.add("#CALC_ERROR", errorData);
|
||||
errorData.add("#REQS", errorReqs);
|
||||
|
||||
// process imports in originCopy
|
||||
|
||||
Importer importer = new Importer(originCopy);
|
||||
List<ImportInfo> imports = importer.findImports();
|
||||
if (!imports.isEmpty()) {
|
||||
final Map<String, JsonObject> factoryJsonMap = new HashMap<>();
|
||||
imports.stream()
|
||||
.forEach(imp->
|
||||
imp.importDescriptors.stream()
|
||||
.filter(id->CommonUtils.isValid(id.factoryId))
|
||||
.forEach(id->factoryJsonMap.put(id.factoryId, null))
|
||||
);
|
||||
boolean inconsistent = false;
|
||||
for (String factoryId: factoryJsonMap.keySet()) {
|
||||
JsonObject factoryJson;
|
||||
if ("#".equals(factoryId))
|
||||
factoryJson = origin;
|
||||
else
|
||||
factoryJson = storage.getConfiguration(factoryId);
|
||||
if (factoryJson == null) {
|
||||
inconsistent = true;
|
||||
errorReqs.add(factoryId);
|
||||
} else {
|
||||
factoryJsonMap.put(factoryId, factoryJson);
|
||||
}
|
||||
|
||||
}
|
||||
if (inconsistent)
|
||||
return error;
|
||||
|
||||
importer.addImportedSources(factoryJsonMap);
|
||||
importer.processImports(imports);
|
||||
|
||||
}
|
||||
|
||||
// process inheritance
|
||||
String parent = getParentFromJson(origin);
|
||||
if (CommonUtils.isValid(parent)) {
|
||||
JsonObject parentObject = storage.getConfiguration(parent);
|
||||
if (parentObject == null) {
|
||||
errorReqs.add(parent);
|
||||
return error;
|
||||
}
|
||||
result = parentObject.deepCopy();
|
||||
prepareTypeInfo(result, originCopy);
|
||||
processObjectOverriding(result, originCopy, OVERRIDE_MODE.UPDATE);
|
||||
} else {
|
||||
result = originCopy;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
private static final Logger log = LoggerFactory.getLogger(EntaxyFactoryUtils.class);
|
||||
|
||||
public static void prepareTypeInfo(JsonObject parent, JsonObject child) {
|
||||
JsonElement parentTypeE = JSONUtils.findElement(parent, "factory.type");
|
||||
JsonElement childTypeE = JSONUtils.findElement(child, "factory.type");
|
||||
String parentType = "";
|
||||
String childType = "";
|
||||
if ((parentTypeE!=null) && parentTypeE.isJsonPrimitive())
|
||||
parentType = parentTypeE.getAsString();
|
||||
if ((childTypeE!=null) && childTypeE.isJsonPrimitive())
|
||||
childType = childTypeE.getAsString();
|
||||
|
||||
JsonObject parentProperties = getTypeProperties(parent);
|
||||
JsonObject childProperties = getTypeProperties(child);
|
||||
if (childProperties==null)
|
||||
return;
|
||||
if (!parentType.equals(childType) && CommonUtils.isValid(childType)) {
|
||||
// copy parent type info with child type
|
||||
parent.add(childType, getTypeProperties(parent).deepCopy());
|
||||
}
|
||||
JsonElement parentHierarchy = JSONUtils.findElement(parentProperties, PROP_HIERARCHY);
|
||||
JsonArray childHierarchy = new JsonArray();
|
||||
if ((parentHierarchy != null) && parentHierarchy.isJsonArray()) {
|
||||
childHierarchy.addAll(parentHierarchy.getAsJsonArray());
|
||||
}
|
||||
childHierarchy.add(JSONUtils.findElement(parent, "factory.id"));
|
||||
childProperties.add(PROP_HIERARCHY, childHierarchy);
|
||||
}
|
||||
|
||||
public static JsonObject resolveVariants(JsonObject root) {
|
||||
JsonObject result = root.deepCopy();
|
||||
processObjectVariants(result, root);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void processObjectVariants(JsonObject currentObject, JsonObject root) {
|
||||
JsonObject variants = getVariants(currentObject);
|
||||
if (variants != null) {
|
||||
String property = variants.has("property")
|
||||
?variants.get("property").getAsString()
|
||||
:"";
|
||||
if (CommonUtils.isValid(property)) {
|
||||
JsonObject values = (variants.has("values") && variants.get("values").isJsonObject())
|
||||
?variants.get("values").getAsJsonObject()
|
||||
:null;
|
||||
if (values != null) {
|
||||
JsonObject typeProperties = getTypeProperties(root);
|
||||
JsonElement je = JSONUtils.findElement(typeProperties, property);
|
||||
if (je != null) {
|
||||
String value = je.getAsString();
|
||||
if (values.has(value) && values.get(value).isJsonObject()) {
|
||||
JsonObject variant = values.get(value).getAsJsonObject();
|
||||
for (Entry<String, JsonElement> entry: variant.entrySet()) {
|
||||
currentObject.remove(entry.getKey());
|
||||
currentObject.add(entry.getKey(), entry.getValue().deepCopy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
currentObject.remove(DIRECTIVES.VARIANTS);
|
||||
}
|
||||
for (Entry<String, JsonElement> entry: currentObject.entrySet()) {
|
||||
if (entry.getValue().isJsonObject())
|
||||
processObjectVariants(entry.getValue().getAsJsonObject(), root);
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonObject getVariants(JsonObject currentObject) {
|
||||
if (currentObject.has(DIRECTIVES.VARIANTS) && currentObject.get(DIRECTIVES.VARIANTS).isJsonObject())
|
||||
return currentObject.get(DIRECTIVES.VARIANTS).getAsJsonObject();
|
||||
return null;
|
||||
}
|
||||
public static final String PROP_HIERARCHY = "hierarchy";
|
||||
|
||||
public static JsonObject getTypeProperties(JsonObject currentObject) {
|
||||
JsonElement type = JSONUtils.findElement(currentObject, "factory.type");
|
||||
if (type == null)
|
||||
return new JsonObject();
|
||||
String typeValue = type.getAsString();
|
||||
if (!CommonUtils.isValid(typeValue))
|
||||
return new JsonObject();
|
||||
JsonElement typeProperties = JSONUtils.findElement(currentObject, typeValue);
|
||||
if (typeProperties.isJsonObject())
|
||||
return typeProperties.getAsJsonObject();
|
||||
return new JsonObject();
|
||||
}
|
||||
|
||||
public static String getParentFromJson(JsonObject jsonObject) {
|
||||
if (!jsonObject.has(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME))
|
||||
return null;
|
||||
JsonObject fs = jsonObject.get(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME).getAsJsonObject();
|
||||
if (fs.has(EntaxyFactory.CONFIGURATION.FACTORY.PARENT))
|
||||
return fs.get(EntaxyFactory.CONFIGURATION.FACTORY.PARENT).getAsString();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void processObjectOverriding(JsonObject currentObject, JsonObject newObject, OVERRIDE_MODE defaultMode) {
|
||||
|
||||
OVERRIDE_MODE mode = getOverrideMode(currentObject, defaultMode);
|
||||
|
||||
Map<String, INHERIT_MODE> inheritMode = getInheritMode(newObject);
|
||||
|
||||
if (currentObject.has(EntaxyFactory.CONFIGURATION.DIRECTIVES.LOCALS)) {
|
||||
try {
|
||||
|
||||
// Locals are not allowed to be inherited
|
||||
// so we fill
|
||||
|
||||
JsonObject locals = currentObject.get(EntaxyFactory.CONFIGURATION.DIRECTIVES.LOCALS).getAsJsonObject();
|
||||
for (Entry<String, JsonElement> entry: locals.entrySet()) {
|
||||
|
||||
try {
|
||||
JsonObject local = entry.getValue().getAsJsonObject();
|
||||
|
||||
JsonElement defaultValue;
|
||||
|
||||
if (local.has("defaultValue"))
|
||||
defaultValue = local.get("defaultValue");
|
||||
else
|
||||
defaultValue = new JsonPrimitive("");
|
||||
|
||||
boolean required = false;
|
||||
if (local.has("required"))
|
||||
required = local.get("required").getAsBoolean();
|
||||
|
||||
if (currentObject.has(entry.getKey())) {
|
||||
currentObject.remove(entry.getKey());
|
||||
currentObject.add(entry.getKey(), defaultValue);
|
||||
} else
|
||||
if (required)
|
||||
currentObject.add(entry.getKey(), defaultValue);
|
||||
|
||||
} catch (Exception localException) {
|
||||
log.warn("Error processing '@LOCALS/" + entry.getKey() + ":", localException);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("Error processing '@LOCALS':", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (OVERRIDE_MODE.IGNORE.equals(mode))
|
||||
return;
|
||||
|
||||
if (OVERRIDE_MODE.REPLACE.equals(mode)) {
|
||||
Set<String> set = new HashSet<String>(currentObject.keySet());
|
||||
for (String entry: set)
|
||||
currentObject.remove(entry);
|
||||
for (Entry<String, JsonElement> entry: newObject.entrySet())
|
||||
currentObject.add(entry.getKey(), entry.getValue().deepCopy());
|
||||
return;
|
||||
}
|
||||
|
||||
if (OVERRIDE_MODE.APPEND.equals(mode)) {
|
||||
for (Entry<String, JsonElement> entry: newObject.entrySet())
|
||||
if (!currentObject.has(entry.getKey()))
|
||||
currentObject.add(entry.getKey(), entry.getValue().deepCopy());
|
||||
return;
|
||||
}
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
public static String getEffectiveJson(EntaxyFactory factory) {
|
||||
JsonObject result = new JsonObject();
|
||||
|
||||
// factory
|
||||
JsonObject factoryData = null;
|
||||
|
||||
JsonObject originJson = JSONUtils.getJsonRootObject(factory.getJsonOrigin());
|
||||
boolean failback = false;
|
||||
if (!originJson.has(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME)) {
|
||||
failback = true;
|
||||
} else {
|
||||
JsonElement je = originJson.get(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME);
|
||||
if (!je.isJsonObject()) {
|
||||
failback = true;
|
||||
} else {
|
||||
factoryData = je.getAsJsonObject().deepCopy();
|
||||
}
|
||||
}
|
||||
|
||||
if (failback) {
|
||||
factoryData = new JsonObject();
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.ID, factory.getId());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.TYPE, factory.getType());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.CATEGORY, factory.getCategory());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.LABEL, factory.getLabel());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.DESCRIPTION, factory.getDescription());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.PARENT, factory.getParent());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.SHORT_NAME, factory.getShortName());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.IS_ABSTRACT, factory.isAbstract());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.IS_DEPRECATED, factory.isDeprecated());
|
||||
factoryData.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.DISPLAY_NAME, factory.getDisplayName());
|
||||
}
|
||||
|
||||
result.add(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME, factoryData);
|
||||
|
||||
// typed data
|
||||
String type = factory.getType();
|
||||
JsonElement typeData = gson.toJsonTree(factory.getTypeInfo());
|
||||
result.add(type, typeData);
|
||||
|
||||
// fields
|
||||
JsonObject fieldsData = new JsonObject();
|
||||
for (FieldInfo fi : factory.getFields()) {
|
||||
fieldsData.add(fi.getName(), fi.getJsonOrigin());
|
||||
}
|
||||
result.add(EntaxyFactory.CONFIGURATION.FIELDS_SECTION_NAME, fieldsData);
|
||||
|
||||
// outputs
|
||||
JsonObject outputsData = new JsonObject();
|
||||
for (OutputInfo oi : factory.getOutputs()) {
|
||||
JsonObject outputData = new JsonObject();
|
||||
outputData.addProperty(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.IS_DEFAULT, oi.isDefault());
|
||||
outputData.addProperty(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.GENERATOR, oi.getGenerator());
|
||||
outputData.add(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.SCOPES, gson.toJsonTree(oi.getScopes()));
|
||||
if (oi.getConfig() != null)
|
||||
outputData.add(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.CONFIG, gson.toJsonTree(oi.getConfig()));
|
||||
JsonObject outputFields = new JsonObject();
|
||||
for (FieldInfo fi : oi.getFields()) {
|
||||
outputFields.add(fi.getName(), fi.getJsonOrigin());
|
||||
}
|
||||
outputData.add(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.FIELDS, outputFields);
|
||||
outputsData.add(oi.getType(), outputData);
|
||||
}
|
||||
result.add(EntaxyFactory.CONFIGURATION.OUTPUTS_SECTION_NAME, outputsData);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static JsonObject cleanJson(JsonObject origin) {
|
||||
JsonObject result = origin.deepCopy();
|
||||
|
||||
cleanObject(result, EntaxyFactory.CONFIGURATION.DIRECTIVES.getDesignDirectives());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void cleanObject(JsonObject origin, Set<String> toRemove) {
|
||||
for (String name : toRemove)
|
||||
origin.remove(name);
|
||||
for (Entry<String, JsonElement> entry : origin.entrySet())
|
||||
if (entry.getValue().isJsonObject())
|
||||
cleanObject(entry.getValue().getAsJsonObject(), toRemove);
|
||||
}
|
||||
|
||||
public static interface FactoryConfigurationStorage {
|
||||
JsonObject getConfiguration(String factoryId);
|
||||
}
|
||||
|
||||
public static JsonObject calculateEffectiveJson(JsonObject origin, FactoryConfigurationStorage storage) {
|
||||
JsonObject originCopy = origin.deepCopy();
|
||||
JsonObject result = originCopy;
|
||||
JsonObject error = new JsonObject();
|
||||
JsonObject errorData = new JsonObject();
|
||||
JsonArray errorReqs = new JsonArray();
|
||||
|
||||
error.add("#CALC_ERROR", errorData);
|
||||
errorData.add("#REQS", errorReqs);
|
||||
|
||||
// process imports in originCopy
|
||||
|
||||
Importer importer = new Importer(originCopy);
|
||||
List<ImportInfo> imports = importer.findImports();
|
||||
if (!imports.isEmpty()) {
|
||||
final Map<String, JsonObject> factoryJsonMap = new HashMap<>();
|
||||
imports.stream()
|
||||
.forEach(imp -> imp.importDescriptors.stream()
|
||||
.filter(id -> CommonUtils.isValid(id.factoryId))
|
||||
.forEach(id -> factoryJsonMap.put(id.factoryId, null)));
|
||||
boolean inconsistent = false;
|
||||
for (String factoryId : factoryJsonMap.keySet()) {
|
||||
JsonObject factoryJson;
|
||||
if ("#".equals(factoryId))
|
||||
factoryJson = origin;
|
||||
else
|
||||
factoryJson = storage.getConfiguration(factoryId);
|
||||
if (factoryJson == null) {
|
||||
inconsistent = true;
|
||||
errorReqs.add(factoryId);
|
||||
} else {
|
||||
factoryJsonMap.put(factoryId, factoryJson);
|
||||
}
|
||||
|
||||
}
|
||||
if (inconsistent)
|
||||
return error;
|
||||
|
||||
importer.addImportedSources(factoryJsonMap);
|
||||
importer.processImports(imports);
|
||||
|
||||
}
|
||||
|
||||
// process inheritance
|
||||
String parent = getParentFromJson(origin);
|
||||
if (CommonUtils.isValid(parent)) {
|
||||
JsonObject parentObject = storage.getConfiguration(parent);
|
||||
if (parentObject == null) {
|
||||
errorReqs.add(parent);
|
||||
return error;
|
||||
}
|
||||
result = parentObject.deepCopy();
|
||||
prepareTypeInfo(result, originCopy);
|
||||
processObjectOverriding(result, originCopy, OVERRIDE_MODE.UPDATE);
|
||||
} else {
|
||||
result = originCopy;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void prepareTypeInfo(JsonObject parent, JsonObject child) {
|
||||
JsonElement parentTypeE = JSONUtils.findElement(parent, "factory.type");
|
||||
JsonElement childTypeE = JSONUtils.findElement(child, "factory.type");
|
||||
String parentType = "";
|
||||
String childType = "";
|
||||
if ((parentTypeE != null) && parentTypeE.isJsonPrimitive())
|
||||
parentType = parentTypeE.getAsString();
|
||||
if ((childTypeE != null) && childTypeE.isJsonPrimitive())
|
||||
childType = childTypeE.getAsString();
|
||||
|
||||
JsonObject parentProperties = getTypeProperties(parent);
|
||||
JsonObject childProperties = getTypeProperties(child);
|
||||
if (childProperties == null)
|
||||
return;
|
||||
if (!parentType.equals(childType) && CommonUtils.isValid(childType)) {
|
||||
// copy parent type info with child type
|
||||
parent.add(childType, getTypeProperties(parent).deepCopy());
|
||||
}
|
||||
JsonElement parentHierarchy = JSONUtils.findElement(parentProperties, PROP_HIERARCHY);
|
||||
JsonArray childHierarchy = new JsonArray();
|
||||
if ((parentHierarchy != null) && parentHierarchy.isJsonArray()) {
|
||||
childHierarchy.addAll(parentHierarchy.getAsJsonArray());
|
||||
}
|
||||
childHierarchy.add(JSONUtils.findElement(parent, "factory.id"));
|
||||
childProperties.add(PROP_HIERARCHY, childHierarchy);
|
||||
}
|
||||
|
||||
public static JsonObject resolveVariants(JsonObject root) {
|
||||
JsonObject result = root.deepCopy();
|
||||
processObjectVariants(result, root);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void processObjectVariants(JsonObject currentObject, JsonObject root) {
|
||||
JsonObject variants = getVariants(currentObject);
|
||||
if (variants != null) {
|
||||
String property = variants.has("property")
|
||||
? variants.get("property").getAsString()
|
||||
: "";
|
||||
if (CommonUtils.isValid(property)) {
|
||||
JsonObject values = (variants.has("values") && variants.get("values").isJsonObject())
|
||||
? variants.get("values").getAsJsonObject()
|
||||
: null;
|
||||
if (values != null) {
|
||||
JsonObject typeProperties = getTypeProperties(root);
|
||||
JsonElement je = JSONUtils.findElement(typeProperties, property);
|
||||
if (je != null) {
|
||||
String value = je.getAsString();
|
||||
if (values.has(value) && values.get(value).isJsonObject()) {
|
||||
JsonObject variant = values.get(value).getAsJsonObject();
|
||||
for (Entry<String, JsonElement> entry : variant.entrySet()) {
|
||||
currentObject.remove(entry.getKey());
|
||||
currentObject.add(entry.getKey(), entry.getValue().deepCopy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
currentObject.remove(DIRECTIVES.VARIANTS);
|
||||
}
|
||||
for (Entry<String, JsonElement> entry : currentObject.entrySet()) {
|
||||
if (entry.getValue().isJsonObject())
|
||||
processObjectVariants(entry.getValue().getAsJsonObject(), root);
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonObject getVariants(JsonObject currentObject) {
|
||||
if (currentObject.has(DIRECTIVES.VARIANTS) && currentObject.get(DIRECTIVES.VARIANTS).isJsonObject())
|
||||
return currentObject.get(DIRECTIVES.VARIANTS).getAsJsonObject();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JsonObject getTypeProperties(JsonObject currentObject) {
|
||||
JsonElement type = JSONUtils.findElement(currentObject, "factory.type");
|
||||
if (type == null)
|
||||
return new JsonObject();
|
||||
String typeValue = type.getAsString();
|
||||
if (!CommonUtils.isValid(typeValue))
|
||||
return new JsonObject();
|
||||
JsonElement typeProperties = JSONUtils.findElement(currentObject, typeValue);
|
||||
if (typeProperties.isJsonObject())
|
||||
return typeProperties.getAsJsonObject();
|
||||
return new JsonObject();
|
||||
}
|
||||
|
||||
public static String getParentFromJson(JsonObject jsonObject) {
|
||||
if (!jsonObject.has(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME))
|
||||
return null;
|
||||
JsonObject fs = jsonObject.get(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME).getAsJsonObject();
|
||||
if (fs.has(EntaxyFactory.CONFIGURATION.FACTORY.PARENT))
|
||||
return fs.get(EntaxyFactory.CONFIGURATION.FACTORY.PARENT).getAsString();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void processObjectOverriding(JsonObject currentObject, JsonObject newObject,
|
||||
OVERRIDE_MODE defaultMode) {
|
||||
|
||||
OVERRIDE_MODE mode = getOverrideMode(currentObject, defaultMode);
|
||||
|
||||
Map<String, INHERIT_MODE> inheritMode = getInheritMode(newObject);
|
||||
|
||||
if (currentObject.has(EntaxyFactory.CONFIGURATION.DIRECTIVES.LOCALS)) {
|
||||
try {
|
||||
|
||||
// Locals are not allowed to be inherited
|
||||
// so we fill
|
||||
|
||||
JsonObject locals = currentObject.get(EntaxyFactory.CONFIGURATION.DIRECTIVES.LOCALS).getAsJsonObject();
|
||||
for (Entry<String, JsonElement> entry : locals.entrySet()) {
|
||||
|
||||
try {
|
||||
JsonObject local = entry.getValue().getAsJsonObject();
|
||||
|
||||
JsonElement defaultValue;
|
||||
|
||||
if (local.has("defaultValue"))
|
||||
defaultValue = local.get("defaultValue");
|
||||
else
|
||||
defaultValue = new JsonPrimitive("");
|
||||
|
||||
boolean required = false;
|
||||
if (local.has("required"))
|
||||
required = local.get("required").getAsBoolean();
|
||||
|
||||
if (currentObject.has(entry.getKey())) {
|
||||
currentObject.remove(entry.getKey());
|
||||
currentObject.add(entry.getKey(), defaultValue);
|
||||
} else if (required)
|
||||
currentObject.add(entry.getKey(), defaultValue);
|
||||
|
||||
} catch (Exception localException) {
|
||||
log.warn("Error processing '@LOCALS/" + entry.getKey() + ":", localException);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("Error processing '@LOCALS':", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (OVERRIDE_MODE.IGNORE.equals(mode))
|
||||
return;
|
||||
|
||||
if (OVERRIDE_MODE.REPLACE.equals(mode)) {
|
||||
Set<String> set = new HashSet<String>(currentObject.keySet());
|
||||
for (String entry : set)
|
||||
currentObject.remove(entry);
|
||||
for (Entry<String, JsonElement> entry : newObject.entrySet())
|
||||
currentObject.add(entry.getKey(), entry.getValue().deepCopy());
|
||||
return;
|
||||
}
|
||||
|
||||
if (OVERRIDE_MODE.APPEND.equals(mode)) {
|
||||
for (Entry<String, JsonElement> entry : newObject.entrySet())
|
||||
if (!currentObject.has(entry.getKey()))
|
||||
currentObject.add(entry.getKey(), entry.getValue().deepCopy());
|
||||
return;
|
||||
}
|
||||
|
||||
if (OVERRIDE_MODE.UPDATE.equals(mode)) {
|
||||
|
||||
|
||||
// update existing
|
||||
Set<String> set = new HashSet<String>(currentObject.keySet());
|
||||
for (String key : set) {
|
||||
if (newObject.has(key)) {
|
||||
JsonElement currentElement = currentObject.get(key);
|
||||
JsonElement newElement = newObject.get(key);
|
||||
if (currentElement.isJsonObject() && newElement.isJsonObject()) {
|
||||
processObjectOverriding(currentElement.getAsJsonObject(), newElement.getAsJsonObject(), mode);
|
||||
} else {
|
||||
if (currentElement.isJsonArray() || newElement.isJsonArray()) {
|
||||
INHERIT_MODE currentInheritMode = inheritMode.getOrDefault(key, INHERIT_MODE.REPLACE);
|
||||
if (!INHERIT_MODE.REPLACE.equals(currentInheritMode)) {
|
||||
processArrayOverriding(currentObject, currentElement, newObject, newElement, key,
|
||||
currentInheritMode);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
currentObject.remove(key);
|
||||
currentObject.add(key, newElement.deepCopy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add new
|
||||
for (Entry<String, JsonElement> entry : newObject.entrySet())
|
||||
if (!currentObject.has(entry.getKey()))
|
||||
currentObject.add(entry.getKey(), entry.getValue().deepCopy());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void processArrayOverriding(JsonObject currentObject, JsonElement currentElement,
|
||||
JsonObject newObject, JsonElement newElement, String elementName, INHERIT_MODE currentInheritMode) {
|
||||
switch (currentInheritMode) {
|
||||
case IGNORE:
|
||||
break;
|
||||
case REPLACE:
|
||||
currentObject.remove(elementName);
|
||||
currentObject.add(elementName, newElement);
|
||||
break;
|
||||
case APPEND:
|
||||
case PREPEND:
|
||||
JsonArray currentArray, newArray;
|
||||
if (currentElement.isJsonArray())
|
||||
currentArray = currentElement.getAsJsonArray();
|
||||
else {
|
||||
currentArray = new JsonArray();
|
||||
currentArray.add(currentElement);
|
||||
}
|
||||
if (newElement.isJsonArray())
|
||||
newArray = newElement.getAsJsonArray();
|
||||
else {
|
||||
newArray = new JsonArray();
|
||||
newArray.add(newElement);
|
||||
}
|
||||
JsonArray firstArray, secondArray;
|
||||
if (INHERIT_MODE.APPEND.equals(currentInheritMode)) {
|
||||
firstArray = currentArray;
|
||||
secondArray = newArray;
|
||||
} else {
|
||||
firstArray = newArray;
|
||||
secondArray = currentArray;
|
||||
}
|
||||
JsonArray result = new JsonArray();
|
||||
result.addAll(firstArray);
|
||||
result.addAll(secondArray);
|
||||
currentObject.remove(elementName);
|
||||
currentObject.add(elementName, result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, EntaxyFactory.CONFIGURATION.DIRECTIVES.INHERIT_MODE> getInheritMode(JsonObject object) {
|
||||
|
||||
Map<String, EntaxyFactory.CONFIGURATION.DIRECTIVES.INHERIT_MODE> result = new HashMap<>();
|
||||
|
||||
if (object.has(EntaxyFactory.CONFIGURATION.DIRECTIVES.INHERIT)) {
|
||||
JsonElement je = object.get(EntaxyFactory.CONFIGURATION.DIRECTIVES.INHERIT);
|
||||
if (je.isJsonPrimitive()) {
|
||||
try {
|
||||
INHERIT_MODE mode = INHERIT_MODE.valueOfLabel(je.getAsString());
|
||||
result.put("*", mode);
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
} else if (je.isJsonObject()) {
|
||||
JsonObject jo = je.getAsJsonObject();
|
||||
for (Entry<String, JsonElement> entry : jo.entrySet()) {
|
||||
try {
|
||||
INHERIT_MODE mode = INHERIT_MODE.valueOfLabel(entry.getValue().getAsString());
|
||||
result.put(entry.getKey(), mode);
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE_MODE getOverrideMode(JsonObject object,
|
||||
OVERRIDE_MODE defaultMode) {
|
||||
OVERRIDE_MODE result = defaultMode;
|
||||
if (object.has(EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE)) {
|
||||
try {
|
||||
OVERRIDE_MODE mode = OVERRIDE_MODE
|
||||
.valueOfLabel(object.get(EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE).getAsString());
|
||||
if (mode != null)
|
||||
result = mode;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<String, Object> getFactoryEssence(EntaxyFactory factory, String prefix) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
JsonObject config = JSONUtils.getJsonRootObject(factory.getJsonConfiguration());
|
||||
|
||||
if (config == null)
|
||||
return result;
|
||||
|
||||
if (!config.has(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME))
|
||||
return result;
|
||||
|
||||
Object obj = JSONUtils.element2object(config.get(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME));
|
||||
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_ID), factory.getId());
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_TYPE), factory.getType());
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_PARENT), factory.getParent());
|
||||
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_SHORT_NAME), factory.getShortName());
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_DISPLAY_NAME), factory.getDisplayName());
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_DESCRIPTION), factory.getDescription());
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_LABEL), factory.getLabel());
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_CATEGORY), factory.getCategory());
|
||||
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_REQUIRES), null);
|
||||
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_IS_ABSTRACT), factory.isAbstract());
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_IS_DEPRECATED), factory.isDeprecated());
|
||||
result.put(String.format("%s%s", prefix, EntaxyFactory.SEARCH.ATTR_IS_INTERNAL), factory.isInternal());
|
||||
|
||||
|
||||
if (!(obj instanceof Map))
|
||||
return result;
|
||||
|
||||
for (Map.Entry<String, Object> entry : ((Map<String, Object>) obj).entrySet()) {
|
||||
String key = String.format("%s%s", prefix, entry.getKey());
|
||||
if (!result.containsKey(key))
|
||||
result.put(key, entry.getValue());
|
||||
}
|
||||
|
||||
result.putAll(factory.getTypeInfo().entrySet().stream()
|
||||
.collect(() -> new LinkedHashMap<String, Object>(),
|
||||
(m, e) -> m.put(String.format("%stypeinfo.%s", prefix, e.getKey()), e.getValue()),
|
||||
HashMap::putAll)
|
||||
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (OVERRIDE_MODE.UPDATE.equals(mode)) {
|
||||
|
||||
|
||||
// update existing
|
||||
Set<String> set = new HashSet<String>(currentObject.keySet());
|
||||
for (String key: set) {
|
||||
if (newObject.has(key)) {
|
||||
JsonElement currentElement = currentObject.get(key);
|
||||
JsonElement newElement = newObject.get(key);
|
||||
if (currentElement.isJsonObject() && newElement.isJsonObject()) {
|
||||
processObjectOverriding(currentElement.getAsJsonObject(), newElement.getAsJsonObject(), mode);
|
||||
} else {
|
||||
if (currentElement.isJsonArray() || newElement.isJsonArray()) {
|
||||
INHERIT_MODE currentInheritMode = inheritMode.getOrDefault(key, INHERIT_MODE.REPLACE);
|
||||
if (!INHERIT_MODE.REPLACE.equals(currentInheritMode)) {
|
||||
processArrayOverriding(currentObject
|
||||
,currentElement
|
||||
,newObject
|
||||
, newElement
|
||||
, key
|
||||
, currentInheritMode);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
currentObject.remove(key);
|
||||
currentObject.add(key, newElement.deepCopy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add new
|
||||
for (Entry<String, JsonElement> entry: newObject.entrySet())
|
||||
if (!currentObject.has(entry.getKey()))
|
||||
currentObject.add(entry.getKey(), entry.getValue().deepCopy());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void processArrayOverriding(JsonObject currentObject, JsonElement currentElement
|
||||
, JsonObject newObject, JsonElement newElement
|
||||
, String elementName
|
||||
, INHERIT_MODE currentInheritMode) {
|
||||
switch (currentInheritMode) {
|
||||
case IGNORE:
|
||||
break;
|
||||
case REPLACE:
|
||||
currentObject.remove(elementName);
|
||||
currentObject.add(elementName, newElement);
|
||||
break;
|
||||
case APPEND:
|
||||
case PREPEND:
|
||||
JsonArray currentArray, newArray;
|
||||
if (currentElement.isJsonArray())
|
||||
currentArray = currentElement.getAsJsonArray();
|
||||
else {
|
||||
currentArray = new JsonArray();
|
||||
currentArray.add(currentElement);
|
||||
}
|
||||
if (newElement.isJsonArray())
|
||||
newArray = newElement.getAsJsonArray();
|
||||
else {
|
||||
newArray = new JsonArray();
|
||||
newArray.add(newElement);
|
||||
}
|
||||
JsonArray firstArray, secondArray;
|
||||
if (INHERIT_MODE.APPEND.equals(currentInheritMode)) {
|
||||
firstArray = currentArray;
|
||||
secondArray = newArray;
|
||||
} else {
|
||||
firstArray = newArray;
|
||||
secondArray = currentArray;
|
||||
}
|
||||
JsonArray result = new JsonArray();
|
||||
result.addAll(firstArray);
|
||||
result.addAll(secondArray);
|
||||
currentObject.remove(elementName);
|
||||
currentObject.add(elementName, result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, EntaxyFactory.CONFIGURATION.DIRECTIVES.INHERIT_MODE> getInheritMode(JsonObject object) {
|
||||
|
||||
Map<String, EntaxyFactory.CONFIGURATION.DIRECTIVES.INHERIT_MODE> result = new HashMap<>();
|
||||
|
||||
if (object.has(EntaxyFactory.CONFIGURATION.DIRECTIVES.INHERIT)) {
|
||||
JsonElement je = object.get(EntaxyFactory.CONFIGURATION.DIRECTIVES.INHERIT);
|
||||
if (je.isJsonPrimitive()) {
|
||||
try {
|
||||
INHERIT_MODE mode = INHERIT_MODE.valueOfLabel(je.getAsString());
|
||||
result.put("*", mode);
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
} else
|
||||
if (je.isJsonObject()) {
|
||||
JsonObject jo = je.getAsJsonObject();
|
||||
for (Entry<String, JsonElement> entry: jo.entrySet()) {
|
||||
try {
|
||||
INHERIT_MODE mode = INHERIT_MODE.valueOfLabel(entry.getValue().getAsString());
|
||||
result.put(entry.getKey(), mode);
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE_MODE getOverrideMode(JsonObject object, OVERRIDE_MODE defaultMode) {
|
||||
OVERRIDE_MODE result = defaultMode;
|
||||
if (object.has(EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE)) {
|
||||
try {
|
||||
OVERRIDE_MODE mode = OVERRIDE_MODE.valueOfLabel(object.get(EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE).getAsString());
|
||||
if (mode != null)
|
||||
result = mode;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -33,6 +33,7 @@ public class FactoryElement extends AbstractElement<FactoryElement> {
|
||||
|
||||
protected String id;
|
||||
protected String type;
|
||||
protected String shortName;
|
||||
protected String displayName;
|
||||
protected String description;
|
||||
protected String label;
|
||||
@ -40,7 +41,8 @@ public class FactoryElement extends AbstractElement<FactoryElement> {
|
||||
|
||||
protected String parent;
|
||||
protected boolean isAbstract = false;
|
||||
protected boolean isDeprecated = false;
|
||||
protected boolean isInternal = false;
|
||||
protected boolean isDeprecated = false;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
@ -54,6 +56,12 @@ public class FactoryElement extends AbstractElement<FactoryElement> {
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
public String getShortName() {
|
||||
return shortName;
|
||||
}
|
||||
public void setShortName(String shortName) {
|
||||
this.shortName = shortName;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -84,6 +92,12 @@ public class FactoryElement extends AbstractElement<FactoryElement> {
|
||||
public void setAbstract(boolean isAbstract) {
|
||||
this.isAbstract = isAbstract;
|
||||
}
|
||||
public boolean isInternal() {
|
||||
return isInternal;
|
||||
}
|
||||
public void setInternal(boolean internal) {
|
||||
isInternal = internal;
|
||||
}
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -37,8 +37,6 @@ import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
@ -60,263 +58,282 @@ import ru.entaxy.platform.base.support.osgi.OSGIUtils;
|
||||
|
||||
public class DefaultFactory implements EntaxyFactory {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DefaultFactory.class);
|
||||
|
||||
protected Map<String, Class<? extends AbstractElement<?>>> elementClasses = new HashMap<>();
|
||||
private static final Logger log = LoggerFactory.getLogger(DefaultFactory.class);
|
||||
|
||||
protected String factoryId = "";
|
||||
|
||||
protected String factoryType = "";
|
||||
protected Map<String, Class<? extends AbstractElement<?>>> elementClasses = new HashMap<>();
|
||||
|
||||
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();
|
||||
|
||||
protected Map<String, Object> factoryData = new HashMap<>();
|
||||
|
||||
protected GenerationHelper helper = null;
|
||||
|
||||
protected JsonObject originJson;
|
||||
|
||||
public DefaultFactory() {
|
||||
super();
|
||||
elementClasses.put(FactoryElement.ELEMENT_NAME, FactoryElement.class);
|
||||
elementClasses.put(OutputsElement.ELEMENT_NAME, OutputsElement.class);
|
||||
elementClasses.put(FieldsElement.ELEMENT_NAME, FieldsElement.class);
|
||||
}
|
||||
|
||||
protected GenerationHelper getHelper() {
|
||||
if (this.helper == null) {
|
||||
try {
|
||||
helper = OSGIUtils.services().ofClass(GenerationHelper.class).waitService(5000).get();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.error("Error getting GenerationHelper", e);
|
||||
}
|
||||
}
|
||||
return this.helper;
|
||||
}
|
||||
|
||||
public void configure(String configuration) {
|
||||
protected String factoryId = "";
|
||||
|
||||
log.debug("CONFIGURE WITH: " + configuration);
|
||||
|
||||
JsonElement je = (new JsonParser()).parse(configuration);
|
||||
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) {
|
||||
String name = entry.getKey();
|
||||
Object result = null;
|
||||
if (elementClasses.containsKey(name)) {
|
||||
log.debug("FOUND element class for [" + name + "] :: " + elementClasses.get(name));
|
||||
try {
|
||||
result = elementClasses.get(name).getConstructor().newInstance().fromJson(entry.getValue());
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
||||
log.error("Error deserializing [" + name + "]", e);
|
||||
continue;
|
||||
}
|
||||
// gson.fromJson(entry.getValue(), elementClasses.get(name));
|
||||
} else
|
||||
result = JSONUtils.element2object(entry.getValue());
|
||||
factoryData.put(name, result);
|
||||
postprocess(name, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void postprocess(String name, Object object) {
|
||||
if (object instanceof FactoryElement) {
|
||||
FactoryElement fe = (FactoryElement)object;
|
||||
log.debug("POSTPROCESS :: FactoryElement");
|
||||
if (CommonUtils.isValid(fe.getId()))
|
||||
this.factoryId = fe.getId();
|
||||
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;
|
||||
log.debug("POSTPROCESS :: Default output config size -> " +
|
||||
this.outputs.getOutput(this.outputs.getDefaultOutputType()).getConfig().size()
|
||||
);
|
||||
if (this.fields != null) {
|
||||
this.outputs.setCommonFields(this.fields.getFieldsMap());
|
||||
log.debug("COMMON FIELDS :: " + this.fields.getFieldsMap().size());
|
||||
} else {
|
||||
log.debug("fields :: null");
|
||||
}
|
||||
} else if (object instanceof FieldsElement) {
|
||||
log.debug("POSTPROCESS :: FieldsElement");
|
||||
this.fields = (FieldsElement)object;
|
||||
if (this.outputs != null) {
|
||||
this.outputs.setCommonFields(this.fields.getFieldsMap());
|
||||
log.debug("COMMON FIELDS :: " + this.fields.getFieldsMap().size());
|
||||
} else {
|
||||
log.debug("outputs :: null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return CommonUtils.isValid(this.factoryId) && CommonUtils.isValid(this.factoryType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.factoryId;
|
||||
}
|
||||
protected String factoryType = "";
|
||||
|
||||
public void setFactoryId(String factoryId) {
|
||||
this.factoryId = factoryId;
|
||||
}
|
||||
protected String description;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return this.factoryType;
|
||||
}
|
||||
protected String shortName;
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
protected String displayName;
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
protected String label;
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
protected String 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);
|
||||
}
|
||||
protected String parent;
|
||||
|
||||
@Override
|
||||
public Generated generate(String outputType, Map<String, Object> parameters) throws EntaxyFactoryException {
|
||||
if (!this.outputs.hasOutput(outputType))
|
||||
throw new OutputNotDefinedException(this, outputType);
|
||||
return this.generate(outputType, EntaxyFactory.SCOPE.PUBLIC.label, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generated generate(String outputType, String scope, Map<String, Object> parameters) throws EntaxyFactoryException {
|
||||
log.debug("Generating for: output type [{}], scope [{}]", outputType, scope);
|
||||
|
||||
if (!this.outputs.hasOutput(outputType)) {
|
||||
log.debug("Factory: {}. Unknown output: {}", this.getId(), outputType);
|
||||
throw new OutputNotDefinedException(this, outputType);
|
||||
}
|
||||
|
||||
OutputElement oe = this.outputs.getOutput(outputType);
|
||||
if (!oe.isScopeSupported(scope)) {
|
||||
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 ScopeNotSupportedException(this
|
||||
, outputType
|
||||
, scope
|
||||
, oe.getSupportedScopes().stream().map(s -> s.label).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
if (this.getHelper() != null)
|
||||
try {
|
||||
return this.getHelper().generateForFactory(this, outputType, SCOPE.valueOfLabel(scope), parameters);
|
||||
} catch (Exception e) {
|
||||
log.error("Generate failed", e);
|
||||
// TODO fill the exception
|
||||
throw new EntaxyFactoryException("Generation failed", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OutputInfo> getOutputs() {
|
||||
return this.outputs.getOutputs().stream().map(el->(OutputInfo)el).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputInfo getOutputByType(String outputType) {
|
||||
return this.outputs.getOutput(outputType);
|
||||
}
|
||||
protected boolean isAbstract;
|
||||
|
||||
@Override
|
||||
public List<FieldInfo> getFields() {
|
||||
return this.fields.getFields().stream().map(f -> (FieldInfo)f).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FieldInfo> getFields(String outputType) {
|
||||
return this.outputs.getOutput(outputType).getFields();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputInfo getDefaultOutput() {
|
||||
return (OutputInfo)outputs.getOutput(outputs.getDefaultOutputType());
|
||||
}
|
||||
protected boolean isInternal;
|
||||
|
||||
protected boolean isDeprecated;
|
||||
|
||||
protected FieldsElement fields = null;
|
||||
|
||||
protected OutputsElement outputs = new OutputsElement();
|
||||
|
||||
protected Map<String, Object> factoryData = new HashMap<>();
|
||||
|
||||
protected GenerationHelper helper = null;
|
||||
|
||||
protected JsonObject originJson;
|
||||
|
||||
public DefaultFactory() {
|
||||
super();
|
||||
elementClasses.put(FactoryElement.ELEMENT_NAME, FactoryElement.class);
|
||||
elementClasses.put(OutputsElement.ELEMENT_NAME, OutputsElement.class);
|
||||
elementClasses.put(FieldsElement.ELEMENT_NAME, FieldsElement.class);
|
||||
}
|
||||
|
||||
protected GenerationHelper getHelper() {
|
||||
if (this.helper == null) {
|
||||
try {
|
||||
helper = OSGIUtils.services().ofClass(GenerationHelper.class).waitService(5000).get();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.error("Error getting GenerationHelper", e);
|
||||
}
|
||||
}
|
||||
return this.helper;
|
||||
}
|
||||
|
||||
public void configure(String configuration) {
|
||||
|
||||
log.debug("CONFIGURE WITH: " + configuration);
|
||||
|
||||
JsonElement je = (new JsonParser()).parse(configuration);
|
||||
JsonObject root = je.getAsJsonObject();
|
||||
|
||||
this.configure(root);
|
||||
}
|
||||
|
||||
public void configure(JsonObject root) {
|
||||
this.originJson = root.deepCopy();
|
||||
|
||||
log.debug("CONFIGURE WITH JSON: " + root.toString());
|
||||
|
||||
Set<Entry<String, JsonElement>> elementSet = root.entrySet();
|
||||
for (Entry<String, JsonElement> entry : elementSet) {
|
||||
String name = entry.getKey();
|
||||
Object result = null;
|
||||
if (elementClasses.containsKey(name)) {
|
||||
log.debug("FOUND element class for [" + name + "] :: " + elementClasses.get(name));
|
||||
try {
|
||||
result = elementClasses.get(name).getConstructor().newInstance().fromJson(entry.getValue());
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
||||
log.error("Error deserializing [" + name + "]", e);
|
||||
continue;
|
||||
}
|
||||
// gson.fromJson(entry.getValue(), elementClasses.get(name));
|
||||
} else
|
||||
result = JSONUtils.element2object(entry.getValue());
|
||||
factoryData.put(name, result);
|
||||
postprocess(name, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void postprocess(String name, Object object) {
|
||||
if (object instanceof FactoryElement) {
|
||||
FactoryElement fe = (FactoryElement) object;
|
||||
log.debug("POSTPROCESS :: FactoryElement");
|
||||
if (CommonUtils.isValid(fe.getId()))
|
||||
this.factoryId = fe.getId();
|
||||
this.factoryType = fe.getType();
|
||||
this.category = fe.getCategory();
|
||||
this.label = fe.getLabel();
|
||||
this.shortName = fe.getShortName();
|
||||
this.displayName = fe.getDisplayName();
|
||||
this.description = fe.getDescription();
|
||||
this.parent = fe.getParent();
|
||||
this.isAbstract = fe.isAbstract();
|
||||
this.isInternal = fe.isInternal();
|
||||
this.isDeprecated = fe.isDeprecated();
|
||||
} else if (object instanceof OutputsElement) {
|
||||
log.debug("POSTPROCESS :: OutputsElement");
|
||||
this.outputs = (OutputsElement) object;
|
||||
log.debug("POSTPROCESS :: Default output config size -> " +
|
||||
this.outputs.getOutput(this.outputs.getDefaultOutputType()).getConfig().size());
|
||||
if (this.fields != null) {
|
||||
this.outputs.setCommonFields(this.fields.getFieldsMap());
|
||||
log.debug("COMMON FIELDS :: " + this.fields.getFieldsMap().size());
|
||||
} else {
|
||||
log.debug("fields :: null");
|
||||
}
|
||||
} else if (object instanceof FieldsElement) {
|
||||
log.debug("POSTPROCESS :: FieldsElement");
|
||||
this.fields = (FieldsElement) object;
|
||||
if (this.outputs != null) {
|
||||
this.outputs.setCommonFields(this.fields.getFieldsMap());
|
||||
log.debug("COMMON FIELDS :: " + this.fields.getFieldsMap().size());
|
||||
} else {
|
||||
log.debug("outputs :: null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return CommonUtils.isValid(this.factoryId) && CommonUtils.isValid(this.factoryType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.factoryId;
|
||||
}
|
||||
|
||||
public void setFactoryId(String factoryId) {
|
||||
this.factoryId = factoryId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return this.factoryType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShortName() {
|
||||
return this.shortName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstract() {
|
||||
return isAbstract;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInternal() {
|
||||
return isInternal;
|
||||
}
|
||||
|
||||
@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 String getJsonOrigin() {
|
||||
return this.originJson.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generated generate(Map<String, Object> parameters) throws EntaxyFactoryException {
|
||||
return generate(this.outputs.getDefaultOutputType(), parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generated generate(String outputType, Map<String, Object> parameters) throws EntaxyFactoryException {
|
||||
if (!this.outputs.hasOutput(outputType))
|
||||
throw new OutputNotDefinedException(this, outputType);
|
||||
return this.generate(outputType, EntaxyFactory.SCOPE.PUBLIC.label, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generated generate(String outputType, String scope, Map<String, Object> parameters)
|
||||
throws EntaxyFactoryException {
|
||||
log.debug("Generating for: output type [{}], scope [{}]", outputType, scope);
|
||||
|
||||
if (!this.outputs.hasOutput(outputType)) {
|
||||
log.debug("Factory: {}. Unknown output: {}", this.getId(), outputType);
|
||||
throw new OutputNotDefinedException(this, outputType);
|
||||
}
|
||||
|
||||
OutputElement oe = this.outputs.getOutput(outputType);
|
||||
if (!oe.isScopeSupported(scope)) {
|
||||
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 ScopeNotSupportedException(this, outputType, scope,
|
||||
oe.getSupportedScopes().stream().map(s -> s.label).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
if (this.getHelper() != null)
|
||||
try {
|
||||
return this.getHelper().generateForFactory(this, outputType, SCOPE.valueOfLabel(scope), parameters);
|
||||
} catch (Exception e) {
|
||||
log.error("Generate failed", e);
|
||||
// TODO fill the exception
|
||||
throw new EntaxyFactoryException("Generation failed", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OutputInfo> getOutputs() {
|
||||
return this.outputs.getOutputs().stream().map(el -> (OutputInfo) el).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputInfo getOutputByType(String outputType) {
|
||||
return this.outputs.getOutput(outputType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FieldInfo> getFields() {
|
||||
return this.fields.getFields().stream().map(f -> (FieldInfo) f).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FieldInfo> getFields(String outputType) {
|
||||
return this.outputs.getOutput(outputType).getFields();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputInfo getDefaultOutput() {
|
||||
return (OutputInfo) outputs.getOutput(outputs.getDefaultOutputType());
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package ru.entaxy.platform.base.objects.factory.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -35,26 +36,33 @@ import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryRegistry;
|
||||
|
||||
@Component (service = FactoryRegistry.class, immediate = true)
|
||||
public class FactoryRegistry {
|
||||
@Component(service = EntaxyFactoryRegistry.class, immediate = true)
|
||||
public class FactoryRegistry implements EntaxyFactoryRegistry {
|
||||
|
||||
protected Map<String, String> inheritance = new HashMap<>();
|
||||
protected Map<String, EntaxyFactory> factories = new HashMap<>();
|
||||
|
||||
@Reference (unbind = "removeFactory", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC
|
||||
, policyOption = ReferencePolicyOption.GREEDY)
|
||||
public void addFactory(EntaxyFactory entaxyFactory) {
|
||||
this.inheritance.put(entaxyFactory.getId(), entaxyFactory.getParent());
|
||||
this.factories.put(entaxyFactory.getId(), entaxyFactory);
|
||||
}
|
||||
|
||||
public void removeFactory(EntaxyFactory entaxyFactory) {
|
||||
this.inheritance.remove(entaxyFactory.getId());
|
||||
this.factories.remove(entaxyFactory.getId());
|
||||
}
|
||||
|
||||
public String getParentFactory(String factoryId) {
|
||||
return this.inheritance.get(factoryId);
|
||||
}
|
||||
protected Map<String, String> inheritance = new HashMap<>();
|
||||
protected Map<String, EntaxyFactory> factories = new HashMap<>();
|
||||
|
||||
@Reference(unbind = "removeFactory", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC,
|
||||
policyOption = ReferencePolicyOption.GREEDY)
|
||||
public void addFactory(EntaxyFactory entaxyFactory) {
|
||||
this.inheritance.put(entaxyFactory.getId(), entaxyFactory.getParent());
|
||||
this.factories.put(entaxyFactory.getId(), entaxyFactory);
|
||||
}
|
||||
|
||||
public void removeFactory(EntaxyFactory entaxyFactory) {
|
||||
this.inheritance.remove(entaxyFactory.getId());
|
||||
this.factories.remove(entaxyFactory.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentFactory(String factoryId) {
|
||||
return this.inheritance.get(factoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<EntaxyFactory> getAllFactories() {
|
||||
return this.factories.values();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -46,6 +46,7 @@ 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.objects.factory.EntaxyFactory;
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryRegistry;
|
||||
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;
|
||||
@ -59,7 +60,7 @@ public class GenerationHelper {
|
||||
protected volatile TemplateService templateService;
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY)
|
||||
FactoryRegistry factoryRegistry;
|
||||
EntaxyFactoryRegistry factoryRegistry;
|
||||
|
||||
public Generated generateForFactory(EntaxyFactory factory, String outputType, SCOPE scope, Map<String, Object> parameters) throws Exception {
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -40,55 +40,55 @@ import ru.entaxy.platform.base.support.JSONUtils;
|
||||
|
||||
public class TrackedFactoryContainer {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TrackedFactoryContainer.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(TrackedFactoryContainer.class);
|
||||
|
||||
private static final String FACTORY_ROOT_PATH = "/ru/entaxy/factory/";
|
||||
|
||||
Bundle bundle;
|
||||
Map<String, TrackedFactory> factories = new LinkedHashMap<>();
|
||||
|
||||
public TrackedFactoryContainer(Bundle bundle) {
|
||||
super();
|
||||
this.bundle = bundle;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
Enumeration<URL> entries = bundle.findEntries(FACTORY_ROOT_PATH, "*.json", true);
|
||||
while (entries.hasMoreElements()) {
|
||||
URL entry = entries.nextElement();
|
||||
String urlString = entry.toString();
|
||||
log.debug("Found path: " + urlString);
|
||||
if (urlString.endsWith("/"))
|
||||
continue;
|
||||
String id = urlString.substring(urlString.lastIndexOf("/") + 1);
|
||||
id = id.substring(0, id.lastIndexOf("."));
|
||||
log.debug("Found id: " + id);
|
||||
|
||||
try {
|
||||
/* String config = new BufferedReader (
|
||||
new InputStreamReader(
|
||||
entry.openStream(), StandardCharsets.UTF_8))
|
||||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
*/
|
||||
String config = JSONUtils.getJsonRootObjectString(entry);
|
||||
if (factories.containsKey(id)) {
|
||||
factories.get(id).setConfigString(config);
|
||||
} else {
|
||||
TrackedFactory tf = new TrackedFactory();
|
||||
tf.setId(id);
|
||||
tf.setBundle(bundle);
|
||||
tf.setConfigString(config);
|
||||
factories.put(id, tf);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error reading url: " + urlString, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<TrackedFactory> getFactoryList(){
|
||||
return new ArrayList<>(this.factories.values());
|
||||
}
|
||||
private static final String FACTORY_ROOT_PATH = "/ru/entaxy/factory/";
|
||||
|
||||
Bundle bundle;
|
||||
Map<String, TrackedFactory> factories = new LinkedHashMap<>();
|
||||
|
||||
public TrackedFactoryContainer(Bundle bundle) {
|
||||
super();
|
||||
this.bundle = bundle;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
Enumeration<URL> entries = bundle.findEntries(FACTORY_ROOT_PATH, "*.json", true);
|
||||
if (entries == null)
|
||||
return;
|
||||
while (entries.hasMoreElements()) {
|
||||
URL entry = entries.nextElement();
|
||||
String urlString = entry.toString();
|
||||
log.debug("Found path: " + urlString);
|
||||
if (urlString.endsWith("/"))
|
||||
continue;
|
||||
String id = urlString.substring(urlString.lastIndexOf("/") + 1);
|
||||
id = id.substring(0, id.lastIndexOf("."));
|
||||
log.debug("Found id: " + id);
|
||||
|
||||
try {
|
||||
/*
|
||||
* String config = new BufferedReader ( new InputStreamReader( entry.openStream(),
|
||||
* StandardCharsets.UTF_8)) .lines() .collect(Collectors.joining("\n"));
|
||||
*/
|
||||
String config = JSONUtils.getJsonRootObjectString(entry);
|
||||
if (factories.containsKey(id)) {
|
||||
factories.get(id).setConfigString(config);
|
||||
} else {
|
||||
TrackedFactory tf = new TrackedFactory();
|
||||
tf.setId(id);
|
||||
tf.setBundle(bundle);
|
||||
tf.setConfigString(config);
|
||||
factories.put(id, tf);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error reading url: " + urlString, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<TrackedFactory> getFactoryList() {
|
||||
return new ArrayList<>(this.factories.values());
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-factory
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -52,418 +52,423 @@ import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.base.support.JSONUtils;
|
||||
import ru.entaxy.platform.base.support.osgi.tracker.BundleTrackerCustomizerListener;
|
||||
|
||||
@Component (service = TrackedFactoryManager.class, immediate = true)
|
||||
public class TrackedFactoryManager implements BundleTrackerCustomizerListener<TrackedFactoryContainer>, FactoryConfigurationStorage {
|
||||
@Component(service = TrackedFactoryManager.class, immediate = true)
|
||||
public class TrackedFactoryManager
|
||||
implements BundleTrackerCustomizerListener<TrackedFactoryContainer>, FactoryConfigurationStorage {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TrackedFactoryManager.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(TrackedFactoryManager.class);
|
||||
|
||||
public static final String DEFAULT_PARENT = "base-object";
|
||||
|
||||
protected BundleContext bundleContext;
|
||||
|
||||
protected Map<String, TrackedManagedFactory> managedFactories = new HashMap<>();
|
||||
|
||||
@Activate
|
||||
public void activate(ComponentContext componentContext) {
|
||||
this.bundleContext = componentContext.getBundleContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void added(TrackedFactoryContainer managedObject) {
|
||||
if (managedObject == null) {
|
||||
log.debug("managedObject is null");
|
||||
return;
|
||||
}
|
||||
|
||||
// List<TrackedManagedFactory> processedFactories = new ArrayList<>();
|
||||
|
||||
FactoryProcessor factoryProcessor = new FactoryProcessor();
|
||||
|
||||
for (TrackedFactory tf: managedObject.getFactoryList()) {
|
||||
log.info("Added factory: " + tf.getId());
|
||||
|
||||
TrackedManagedFactory tmf;
|
||||
|
||||
try {
|
||||
tmf = new TrackedManagedFactory(tf);
|
||||
} catch (Exception e) {
|
||||
log.error("Error creating tracked factory: [" + tf.getId() + "]", e);
|
||||
continue;
|
||||
}
|
||||
|
||||
// if we already have factory with the same id
|
||||
if (managedFactories.containsKey(tmf.factoryId)) {
|
||||
tmf = managedFactories.get(tmf.factoryId);
|
||||
|
||||
// remove old service
|
||||
tmf.deactivate();
|
||||
|
||||
try {
|
||||
tmf.reload(tf);
|
||||
} catch (Exception e) {
|
||||
log.error("Error processing tracked factory: [" + tf.getId() + "]", e);
|
||||
continue;
|
||||
}
|
||||
public static final String DEFAULT_PARENT = "base-object";
|
||||
|
||||
tmf.detachParent();
|
||||
protected BundleContext bundleContext;
|
||||
|
||||
tmf.detachRequirements();
|
||||
|
||||
} else {
|
||||
this.managedFactories.put(tmf.factoryId, tmf);
|
||||
}
|
||||
protected Map<String, TrackedManagedFactory> managedFactories = new HashMap<>();
|
||||
|
||||
if (!CommonUtils.isValid(tmf.parent) && !DEFAULT_PARENT.equalsIgnoreCase(tmf.factoryId)) {
|
||||
tmf.setParent(DEFAULT_PARENT);
|
||||
}
|
||||
|
||||
if (CommonUtils.isValid(tmf.parent)) {
|
||||
TrackedManagedFactory parentF = managedFactories.get(tmf.parent);
|
||||
if ((parentF != null) && parentF.isActive) {
|
||||
tmf.attachParent(parentF);
|
||||
} else {
|
||||
tmf.addWaiting(tmf.parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (String requirement: tmf.requirements) {
|
||||
TrackedManagedFactory req = managedFactories.get(requirement);
|
||||
if (req != null)
|
||||
tmf.attachRequirement(req);
|
||||
else
|
||||
tmf.addWaiting(requirement);
|
||||
}
|
||||
|
||||
if (tmf.isConsistent())
|
||||
factoryProcessor.add(tmf);
|
||||
|
||||
|
||||
|
||||
// processedFactories.add(tmf);
|
||||
|
||||
}
|
||||
|
||||
factoryProcessor.process();
|
||||
|
||||
/*log.debug("Added factory: " + tf.getId());
|
||||
if (TrackedFactory.trackedFactoriesMap.containsKey(tf.getId())) {
|
||||
TrackedFactory.trackedFactoriesMap.get(tf.getId()).unregister();
|
||||
}
|
||||
DefaultFactory defaultFactory = new DefaultFactory();
|
||||
defaultFactory.setFactoryId(tf.getId());
|
||||
defaultFactory.configure(tf.getConfigString());
|
||||
if (defaultFactory.isValid()) {
|
||||
protected Object managedFactoriesLock = new Object();
|
||||
|
||||
tf.setId(defaultFactory.getFactoryId());
|
||||
|
||||
Dictionary<String, String> props = new Hashtable<String, String>();
|
||||
props.put(EntaxyFactory.SERVICE.PROP_ID, defaultFactory.getFactoryId());
|
||||
props.put(EntaxyFactory.SERVICE.PROP_TYPE, defaultFactory.getFactoryType());
|
||||
props.put(EntaxyFactory.SERVICE.PROP_ORIGIN_BUNDLE, tf.getBundle().getBundleId()+"");
|
||||
|
||||
tf.setServiceRegistration(
|
||||
this.bundleContext.registerService(EntaxyFactory.class, defaultFactory, props)
|
||||
);
|
||||
|
||||
TrackedFactory.trackedFactoriesMap.put(tf.getId(), tf);
|
||||
}*/
|
||||
@Activate
|
||||
public void activate(ComponentContext componentContext) {
|
||||
this.bundleContext = componentContext.getBundleContext();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modified(TrackedFactoryContainer managedObject) {
|
||||
if (managedObject == null)
|
||||
return;
|
||||
removed(managedObject);
|
||||
managedObject.reload();
|
||||
added(managedObject);
|
||||
}
|
||||
@Override
|
||||
public void added(TrackedFactoryContainer managedObject) {
|
||||
if (managedObject == null) {
|
||||
log.debug("managedObject is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed(TrackedFactoryContainer managedObject) {
|
||||
if (managedObject == null)
|
||||
return;
|
||||
for (TrackedFactory tf: managedObject.getFactoryList()) {
|
||||
try {
|
||||
tf.getServiceRegistration().unregister();
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
TrackedFactory.trackedFactoriesMap.remove(tf.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// implement FactoryConfigurationStorage
|
||||
public JsonObject getConfiguration(String factoryId) {
|
||||
TrackedManagedFactory tmf = managedFactories.get(factoryId);
|
||||
if (tmf == null)
|
||||
return null;
|
||||
if (!tmf.isConsistent() || !tmf.isUpToDate)
|
||||
return null;
|
||||
return tmf.jsonEffective;
|
||||
};
|
||||
|
||||
public List<TrackedManagedFactory> getManagedFactories() {
|
||||
return new ArrayList<>(this.managedFactories.values());
|
||||
}
|
||||
// List<TrackedManagedFactory> processedFactories = new ArrayList<>();
|
||||
|
||||
synchronized (managedFactoriesLock) {
|
||||
|
||||
FactoryProcessor factoryProcessor = new FactoryProcessor();
|
||||
|
||||
for (TrackedFactory tf : managedObject.getFactoryList()) {
|
||||
log.info("Added factory: " + tf.getId());
|
||||
|
||||
TrackedManagedFactory tmf;
|
||||
|
||||
try {
|
||||
tmf = new TrackedManagedFactory(tf);
|
||||
} catch (Exception e) {
|
||||
log.error("Error creating tracked factory: [" + tf.getId() + "]", e);
|
||||
continue;
|
||||
}
|
||||
|
||||
// if we already have factory with the same id
|
||||
if (managedFactories.containsKey(tmf.factoryId)) {
|
||||
tmf = managedFactories.get(tmf.factoryId);
|
||||
|
||||
// remove old service
|
||||
tmf.deactivate();
|
||||
|
||||
try {
|
||||
tmf.reload(tf);
|
||||
} catch (Exception e) {
|
||||
log.error("Error processing tracked factory: [" + tf.getId() + "]", e);
|
||||
continue;
|
||||
}
|
||||
|
||||
tmf.detachParent();
|
||||
|
||||
tmf.detachRequirements();
|
||||
|
||||
} else {
|
||||
this.managedFactories.put(tmf.factoryId, tmf);
|
||||
}
|
||||
|
||||
if (!CommonUtils.isValid(tmf.parent) && !DEFAULT_PARENT.equalsIgnoreCase(tmf.factoryId)) {
|
||||
tmf.setParent(DEFAULT_PARENT);
|
||||
}
|
||||
|
||||
if (CommonUtils.isValid(tmf.parent)) {
|
||||
TrackedManagedFactory parentF = managedFactories.get(tmf.parent);
|
||||
if ((parentF != null) && parentF.isActive) {
|
||||
tmf.attachParent(parentF);
|
||||
} else {
|
||||
tmf.addWaiting(tmf.parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (String requirement : tmf.requirements) {
|
||||
TrackedManagedFactory req = managedFactories.get(requirement);
|
||||
if (req != null)
|
||||
tmf.attachRequirement(req);
|
||||
else
|
||||
tmf.addWaiting(requirement);
|
||||
}
|
||||
|
||||
if (tmf.isConsistent())
|
||||
factoryProcessor.add(tmf);
|
||||
|
||||
|
||||
|
||||
// processedFactories.add(tmf);
|
||||
|
||||
protected class FactoryProcessor {
|
||||
|
||||
List<TrackedManagedFactory> factories = new ArrayList<>();
|
||||
|
||||
public void add(TrackedManagedFactory tmf) {
|
||||
synchronized (factories) {
|
||||
if (!factories.contains(tmf))
|
||||
factories.add(tmf);
|
||||
}
|
||||
}
|
||||
|
||||
public void process() {
|
||||
while (!this.factories.isEmpty()) {
|
||||
|
||||
List<TrackedManagedFactory> processed = new ArrayList<>();
|
||||
List<TrackedManagedFactory> toProcess = new ArrayList<>();
|
||||
|
||||
for (TrackedManagedFactory currentFactory: factories) {
|
||||
processFactory(currentFactory);
|
||||
if (currentFactory.isActive) {
|
||||
processed.add(currentFactory);
|
||||
|
||||
for (TrackedManagedFactory waitingFactory: managedFactories.values())
|
||||
if (waitingFactory.isWaiting(currentFactory.factoryId)) {
|
||||
waitingFactory.stopWaiting(currentFactory.factoryId);
|
||||
if (waitingFactory.isConsistent())
|
||||
toProcess.add(waitingFactory);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (processed.isEmpty())
|
||||
break;
|
||||
|
||||
for (TrackedManagedFactory tmf: toProcess)
|
||||
if (!this.factories.contains(tmf))
|
||||
this.factories.add(tmf);
|
||||
|
||||
for (TrackedManagedFactory tmf: processed)
|
||||
this.factories.remove(tmf);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void processFactory(TrackedManagedFactory factory) {
|
||||
if (factory.isConsistent()) {
|
||||
|
||||
if (CommonUtils.isValid(factory.parent)) {
|
||||
TrackedManagedFactory parentF = managedFactories.get(factory.parent);
|
||||
factory.attachParent(parentF);
|
||||
}
|
||||
|
||||
for (String requirement: factory.requirements) {
|
||||
TrackedManagedFactory req = managedFactories.get(requirement);
|
||||
factory.attachRequirement(req);
|
||||
}
|
||||
|
||||
|
||||
JsonObject effective = EntaxyFactoryUtils.calculateEffectiveJson(factory.jsonOrigin, TrackedFactoryManager.this);
|
||||
if (!effective.has("#CALC_ERROR")) {
|
||||
factoryProcessor.process();
|
||||
|
||||
factory.jsonEffective = effective.deepCopy();
|
||||
JsonObject jsonFinal = EntaxyFactoryUtils.resolveVariants(effective);
|
||||
|
||||
// create factory
|
||||
factory.updateConfiguration(jsonFinal);
|
||||
if (createFactory(factory)) {
|
||||
factory.activate();
|
||||
}
|
||||
|
||||
} else {
|
||||
JsonObject jo = effective.get("#CALC_ERROR").getAsJsonObject();
|
||||
if (jo.has("#REQS")) {
|
||||
JsonArray ja = jo.get("#REQS").getAsJsonArray();
|
||||
|
||||
final TrackedManagedFactory tmfF = factory;
|
||||
ja.forEach(item->tmfF.addRequirement(item.getAsString()));
|
||||
ja.forEach(item->tmfF.addWaiting(item.getAsString()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.info("Factory {} is inconsistent, waiting for: {}"
|
||||
, factory.factoryId
|
||||
, factory.waitingFor.stream().collect(Collectors.joining(",")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean createFactory(TrackedManagedFactory factory) {
|
||||
DefaultFactory defaultFactory = new DefaultFactory();
|
||||
defaultFactory.setFactoryId(factory.factoryId);
|
||||
defaultFactory.configure(EntaxyFactoryUtils.cleanJson(factory.jsonFinal));
|
||||
if (defaultFactory.isValid()) {
|
||||
|
||||
// to ensure id is correct
|
||||
factory.trackedFactory.setId(defaultFactory.getId());
|
||||
|
||||
Dictionary<String, String> props = new Hashtable<String, String>();
|
||||
props.put(EntaxyFactory.SERVICE.PROP_ID, defaultFactory.getId());
|
||||
props.put(EntaxyFactory.SERVICE.PROP_TYPE, defaultFactory.getType());
|
||||
props.put(EntaxyFactory.SERVICE.PROP_ORIGIN_BUNDLE, factory.trackedFactory.getBundle().getBundleId()+"");
|
||||
|
||||
factory.trackedFactory.setServiceRegistration(
|
||||
TrackedFactoryManager.this.bundleContext.registerService(EntaxyFactory.class, defaultFactory, props)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class TrackedManagedFactory {
|
||||
|
||||
TrackedFactory trackedFactory;
|
||||
|
||||
// original JSON description
|
||||
JsonObject jsonOrigin;
|
||||
// JSON with inheritance & imports resolved
|
||||
JsonObject jsonEffective;
|
||||
// JSON with VARIANTS resolved
|
||||
public JsonObject jsonFinal;
|
||||
|
||||
JsonObject jsonFactorySection = null;
|
||||
|
||||
public String factoryId = null;
|
||||
public String parent = null;
|
||||
|
||||
public List<String> requirements = new ArrayList<>();
|
||||
|
||||
TrackedManagedFactory parentFactory = null;
|
||||
List<TrackedManagedFactory> requiredFactories = new ArrayList<>();
|
||||
List<TrackedManagedFactory> affectedFactories = new ArrayList<>();
|
||||
|
||||
public List<String> waitingFor = new ArrayList<>();
|
||||
|
||||
public boolean isUpToDate = false;
|
||||
|
||||
public boolean isActive = false;
|
||||
|
||||
public TrackedManagedFactory(TrackedFactory factory) throws Exception {
|
||||
reload(factory);
|
||||
}
|
||||
|
||||
public void reload(TrackedFactory factory) throws Exception {
|
||||
this.jsonFactorySection = null;
|
||||
this.factoryId = null;
|
||||
this.parent = null;
|
||||
this.requirements = new ArrayList<>();
|
||||
this.trackedFactory = factory;
|
||||
this.waitingFor.clear();
|
||||
this.jsonOrigin = JSONUtils.getJsonRootObjectUnsafe(this.trackedFactory.getConfigString());
|
||||
if (this.jsonOrigin.has(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME)) {
|
||||
this.jsonFactorySection = this.jsonOrigin.get(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME).getAsJsonObject();
|
||||
if (this.jsonFactorySection.has(EntaxyFactory.CONFIGURATION.FACTORY.ID))
|
||||
this.factoryId = this.jsonFactorySection.get(EntaxyFactory.CONFIGURATION.FACTORY.ID).getAsString();
|
||||
if (this.jsonFactorySection.has(EntaxyFactory.CONFIGURATION.FACTORY.PARENT))
|
||||
this.parent = this.jsonFactorySection.get(EntaxyFactory.CONFIGURATION.FACTORY.PARENT).getAsString();
|
||||
if (this.jsonFactorySection.has(EntaxyFactory.CONFIGURATION.FACTORY.REQUIRES)) {
|
||||
JsonElement je = this.jsonFactorySection.get(EntaxyFactory.CONFIGURATION.FACTORY.REQUIRES);
|
||||
if (je.isJsonArray()) {
|
||||
JsonArray ja = je.getAsJsonArray();
|
||||
ja.forEach(item->this.requirements.add(item.getAsString()));
|
||||
}
|
||||
if (je.isJsonPrimitive()) {
|
||||
this.requirements.add(je.getAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return CommonUtils.isValid(factoryId);
|
||||
}
|
||||
|
||||
public void setParent(String parentValue) {
|
||||
this.parent = parentValue;
|
||||
JsonObject fs = this.jsonOrigin.get(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME).getAsJsonObject();
|
||||
fs.remove(EntaxyFactory.CONFIGURATION.FACTORY.PARENT);
|
||||
fs.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.PARENT, parentValue);
|
||||
}
|
||||
|
||||
public void attachParent(TrackedManagedFactory parentTmf) {
|
||||
if (this.parentFactory != parentTmf)
|
||||
detachParent();
|
||||
this.parentFactory = parentTmf;
|
||||
parentTmf.attachAffected(this);
|
||||
this.isUpToDate = false;
|
||||
}
|
||||
|
||||
public void detachParent() {
|
||||
if (this.parentFactory != null) {
|
||||
this.parentFactory.detachAffected(this);
|
||||
this.parentFactory = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addRequirement(String req) {
|
||||
if (!this.requirements.contains(req))
|
||||
this.requirements.add(req);
|
||||
}
|
||||
public void attachRequirement(TrackedManagedFactory requiredTmf) {
|
||||
if (!this.requiredFactories.contains(requiredTmf))
|
||||
this.requiredFactories.add(requiredTmf);
|
||||
requiredTmf.attachAffected(this);
|
||||
}
|
||||
public void detachRequirements() {
|
||||
for (TrackedManagedFactory tmf: requiredFactories)
|
||||
tmf.detachAffected(this);
|
||||
this.requiredFactories.clear();
|
||||
}
|
||||
|
||||
public void attachAffected(TrackedManagedFactory affectedTmf) {
|
||||
if (!this.affectedFactories.contains(affectedTmf))
|
||||
this.affectedFactories.add(affectedTmf);
|
||||
}
|
||||
public void detachAffected(TrackedManagedFactory affectedTmf) {
|
||||
this.affectedFactories.remove(affectedTmf);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modified(TrackedFactoryContainer managedObject) {
|
||||
if (managedObject == null)
|
||||
return;
|
||||
removed(managedObject);
|
||||
managedObject.reload();
|
||||
added(managedObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed(TrackedFactoryContainer managedObject) {
|
||||
if (managedObject == null)
|
||||
return;
|
||||
|
||||
synchronized (managedFactoriesLock) {
|
||||
for (TrackedFactory tf : managedObject.getFactoryList()) {
|
||||
try {
|
||||
tf.getServiceRegistration().unregister();
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
TrackedFactory.trackedFactoriesMap.remove(tf.getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// implement FactoryConfigurationStorage
|
||||
public JsonObject getConfiguration(String factoryId) {
|
||||
TrackedManagedFactory tmf = managedFactories.get(factoryId);
|
||||
if (tmf == null)
|
||||
return null;
|
||||
if (!tmf.isConsistent() || !tmf.isUpToDate)
|
||||
return null;
|
||||
return tmf.jsonEffective;
|
||||
};
|
||||
|
||||
public List<TrackedManagedFactory> getManagedFactories() {
|
||||
return new ArrayList<>(this.managedFactories.values());
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected class FactoryProcessor {
|
||||
|
||||
List<TrackedManagedFactory> factories = new ArrayList<>();
|
||||
|
||||
public void add(TrackedManagedFactory tmf) {
|
||||
synchronized (factories) {
|
||||
if (!factories.contains(tmf))
|
||||
factories.add(tmf);
|
||||
}
|
||||
}
|
||||
|
||||
public void process() {
|
||||
while (!this.factories.isEmpty()) {
|
||||
|
||||
List<TrackedManagedFactory> processed = new ArrayList<>();
|
||||
List<TrackedManagedFactory> toProcess = new ArrayList<>();
|
||||
|
||||
for (TrackedManagedFactory currentFactory : factories) {
|
||||
processFactory(currentFactory);
|
||||
if (currentFactory.isActive) {
|
||||
processed.add(currentFactory);
|
||||
|
||||
for (TrackedManagedFactory otherFactory : managedFactories.values()) {
|
||||
|
||||
// process waiting factories
|
||||
if (otherFactory.isWaiting(currentFactory.factoryId)) {
|
||||
otherFactory.stopWaiting(currentFactory.factoryId);
|
||||
if (otherFactory.isConsistent())
|
||||
toProcess.add(otherFactory);
|
||||
} else {
|
||||
// cascade process consistent child factories
|
||||
if (otherFactory.parentFactory == currentFactory) {
|
||||
if (otherFactory.isConsistent())
|
||||
toProcess.add(otherFactory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (processed.isEmpty())
|
||||
break;
|
||||
|
||||
for (TrackedManagedFactory tmf : toProcess)
|
||||
if (!this.factories.contains(tmf))
|
||||
this.factories.add(tmf);
|
||||
|
||||
for (TrackedManagedFactory tmf : processed)
|
||||
this.factories.remove(tmf);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void processFactory(TrackedManagedFactory factory) {
|
||||
if (factory.isConsistent()) {
|
||||
|
||||
if (CommonUtils.isValid(factory.parent)) {
|
||||
TrackedManagedFactory parentF = managedFactories.get(factory.parent);
|
||||
factory.attachParent(parentF);
|
||||
}
|
||||
|
||||
for (String requirement : factory.requirements) {
|
||||
TrackedManagedFactory req = managedFactories.get(requirement);
|
||||
factory.attachRequirement(req);
|
||||
}
|
||||
|
||||
|
||||
JsonObject effective =
|
||||
EntaxyFactoryUtils.calculateEffectiveJson(factory.jsonOrigin, TrackedFactoryManager.this);
|
||||
if (!effective.has("#CALC_ERROR")) {
|
||||
|
||||
factory.jsonEffective = effective.deepCopy();
|
||||
JsonObject jsonFinal = EntaxyFactoryUtils.resolveVariants(effective);
|
||||
|
||||
// create factory
|
||||
factory.updateConfiguration(jsonFinal);
|
||||
if (createFactory(factory)) {
|
||||
factory.activate();
|
||||
}
|
||||
|
||||
} else {
|
||||
JsonObject jo = effective.get("#CALC_ERROR").getAsJsonObject();
|
||||
if (jo.has("#REQS")) {
|
||||
JsonArray ja = jo.get("#REQS").getAsJsonArray();
|
||||
|
||||
final TrackedManagedFactory tmfF = factory;
|
||||
ja.forEach(item -> tmfF.addRequirement(item.getAsString()));
|
||||
ja.forEach(item -> tmfF.addWaiting(item.getAsString()));
|
||||
log.info("Factory {} is inconsistent, waiting for: {}", factory.factoryId,
|
||||
factory.waitingFor.stream().collect(Collectors.joining(",")));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.info("Factory {} is inconsistent, waiting for: {}", factory.factoryId,
|
||||
factory.waitingFor.stream().collect(Collectors.joining(",")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean createFactory(TrackedManagedFactory factory) {
|
||||
DefaultFactory defaultFactory = new DefaultFactory();
|
||||
defaultFactory.setFactoryId(factory.factoryId);
|
||||
defaultFactory.configure(EntaxyFactoryUtils.cleanJson(factory.jsonFinal));
|
||||
if (defaultFactory.isValid()) {
|
||||
|
||||
// to ensure id is correct
|
||||
factory.trackedFactory.setId(defaultFactory.getId());
|
||||
|
||||
Dictionary<String, String> props = new Hashtable<String, String>();
|
||||
props.put(EntaxyFactory.SERVICE.PROP_ID, defaultFactory.getId());
|
||||
props.put(EntaxyFactory.SERVICE.PROP_TYPE, defaultFactory.getType());
|
||||
props.put(EntaxyFactory.SERVICE.PROP_ORIGIN_BUNDLE,
|
||||
factory.trackedFactory.getBundle().getBundleId() + "");
|
||||
|
||||
factory.trackedFactory.setServiceRegistration(
|
||||
TrackedFactoryManager.this.bundleContext.registerService(EntaxyFactory.class, defaultFactory,
|
||||
props));
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class TrackedManagedFactory {
|
||||
|
||||
TrackedFactory trackedFactory;
|
||||
|
||||
// original JSON description
|
||||
JsonObject jsonOrigin;
|
||||
// JSON with inheritance & imports resolved
|
||||
JsonObject jsonEffective;
|
||||
// JSON with VARIANTS resolved
|
||||
public JsonObject jsonFinal;
|
||||
|
||||
JsonObject jsonFactorySection = null;
|
||||
|
||||
public String factoryId = null;
|
||||
public String parent = null;
|
||||
|
||||
public List<String> requirements = new ArrayList<>();
|
||||
|
||||
TrackedManagedFactory parentFactory = null;
|
||||
List<TrackedManagedFactory> requiredFactories = new ArrayList<>();
|
||||
List<TrackedManagedFactory> affectedFactories = new ArrayList<>();
|
||||
|
||||
public List<String> waitingFor = new ArrayList<>();
|
||||
|
||||
public boolean isUpToDate = false;
|
||||
|
||||
public boolean isActive = false;
|
||||
|
||||
public TrackedManagedFactory(TrackedFactory factory) throws Exception {
|
||||
reload(factory);
|
||||
}
|
||||
|
||||
public void reload(TrackedFactory factory) throws Exception {
|
||||
this.jsonFactorySection = null;
|
||||
this.factoryId = null;
|
||||
this.parent = null;
|
||||
this.requirements = new ArrayList<>();
|
||||
this.trackedFactory = factory;
|
||||
this.waitingFor.clear();
|
||||
this.jsonOrigin = JSONUtils.getJsonRootObjectUnsafe(this.trackedFactory.getConfigString());
|
||||
if (this.jsonOrigin.has(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME)) {
|
||||
this.jsonFactorySection =
|
||||
this.jsonOrigin.get(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME).getAsJsonObject();
|
||||
if (this.jsonFactorySection.has(EntaxyFactory.CONFIGURATION.FACTORY.ID))
|
||||
this.factoryId = this.jsonFactorySection.get(EntaxyFactory.CONFIGURATION.FACTORY.ID).getAsString();
|
||||
if (this.jsonFactorySection.has(EntaxyFactory.CONFIGURATION.FACTORY.PARENT))
|
||||
this.parent = this.jsonFactorySection.get(EntaxyFactory.CONFIGURATION.FACTORY.PARENT).getAsString();
|
||||
if (this.jsonFactorySection.has(EntaxyFactory.CONFIGURATION.FACTORY.REQUIRES)) {
|
||||
JsonElement je = this.jsonFactorySection.get(EntaxyFactory.CONFIGURATION.FACTORY.REQUIRES);
|
||||
if (je.isJsonArray()) {
|
||||
JsonArray ja = je.getAsJsonArray();
|
||||
ja.forEach(item -> this.requirements.add(item.getAsString()));
|
||||
}
|
||||
if (je.isJsonPrimitive()) {
|
||||
this.requirements.add(je.getAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return CommonUtils.isValid(factoryId);
|
||||
}
|
||||
|
||||
public void setParent(String parentValue) {
|
||||
this.parent = parentValue;
|
||||
JsonObject fs = this.jsonOrigin.get(EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME).getAsJsonObject();
|
||||
fs.remove(EntaxyFactory.CONFIGURATION.FACTORY.PARENT);
|
||||
fs.addProperty(EntaxyFactory.CONFIGURATION.FACTORY.PARENT, parentValue);
|
||||
}
|
||||
|
||||
public void attachParent(TrackedManagedFactory parentTmf) {
|
||||
if (this.parentFactory != parentTmf)
|
||||
detachParent();
|
||||
this.parentFactory = parentTmf;
|
||||
parentTmf.attachAffected(this);
|
||||
this.isUpToDate = false;
|
||||
}
|
||||
|
||||
public void detachParent() {
|
||||
if (this.parentFactory != null) {
|
||||
this.parentFactory.detachAffected(this);
|
||||
this.parentFactory = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addRequirement(String req) {
|
||||
if (!this.requirements.contains(req))
|
||||
this.requirements.add(req);
|
||||
}
|
||||
|
||||
public void attachRequirement(TrackedManagedFactory requiredTmf) {
|
||||
if (!this.requiredFactories.contains(requiredTmf))
|
||||
this.requiredFactories.add(requiredTmf);
|
||||
requiredTmf.attachAffected(this);
|
||||
}
|
||||
|
||||
public void detachRequirements() {
|
||||
for (TrackedManagedFactory tmf : requiredFactories)
|
||||
tmf.detachAffected(this);
|
||||
this.requiredFactories.clear();
|
||||
}
|
||||
|
||||
public void attachAffected(TrackedManagedFactory affectedTmf) {
|
||||
if (!this.affectedFactories.contains(affectedTmf))
|
||||
this.affectedFactories.add(affectedTmf);
|
||||
}
|
||||
|
||||
public void detachAffected(TrackedManagedFactory affectedTmf) {
|
||||
this.affectedFactories.remove(affectedTmf);
|
||||
}
|
||||
|
||||
public void addWaiting(String waitFactoryId) {
|
||||
if (!this.waitingFor.contains(waitFactoryId))
|
||||
this.waitingFor.add(waitFactoryId);
|
||||
}
|
||||
|
||||
public boolean isWaiting(String waitFactoryId) {
|
||||
return this.waitingFor.contains(waitFactoryId);
|
||||
}
|
||||
|
||||
public void stopWaiting(String waitFactoryId) {
|
||||
this.waitingFor.remove(waitFactoryId);
|
||||
}
|
||||
|
||||
public boolean isConsistent() {
|
||||
return this.waitingFor.isEmpty();
|
||||
}
|
||||
|
||||
public void updateConfiguration(JsonObject jsonObject) {
|
||||
this.jsonFinal = jsonObject.deepCopy();
|
||||
this.isUpToDate = true;
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
this.isActive = true;
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
this.trackedFactory.unregister();
|
||||
this.isActive = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addWaiting(String waitFactoryId) {
|
||||
if (!this.waitingFor.contains(waitFactoryId))
|
||||
this.waitingFor.add(waitFactoryId);
|
||||
}
|
||||
public boolean isWaiting(String waitFactoryId) {
|
||||
return this.waitingFor.contains(waitFactoryId);
|
||||
}
|
||||
public void stopWaiting(String waitFactoryId) {
|
||||
this.waitingFor.remove(waitFactoryId);
|
||||
}
|
||||
|
||||
public boolean isConsistent() {
|
||||
return this.waitingFor.isEmpty();
|
||||
}
|
||||
|
||||
public void updateConfiguration(JsonObject jsonObject) {
|
||||
this.jsonFinal = jsonObject.deepCopy();
|
||||
this.isUpToDate = true;
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
this.isActive = true;
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
this.trackedFactory.unregister();
|
||||
this.isActive = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -7,80 +7,109 @@
|
||||
"isAbstract": true,
|
||||
"label": "object",
|
||||
"@LOCALS": {
|
||||
"displayName": {
|
||||
"defaultValue": "",
|
||||
"required": true
|
||||
}
|
||||
"displayName": {
|
||||
"defaultValue": "",
|
||||
"required": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"entaxy.runtime.object": {
|
||||
"isEntaxyObject": true
|
||||
"isEntaxyObject": true
|
||||
},
|
||||
"fields": {
|
||||
"objectId": {
|
||||
"displayName": "Object Id",
|
||||
"type": "String",
|
||||
"required": true,
|
||||
"immutable": true,
|
||||
"@TYPEINFO": {
|
||||
"validation": {
|
||||
"rules": [
|
||||
{
|
||||
"length": {
|
||||
"min": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": {
|
||||
"regex": "^[a-zA-Z][a-zA-Z0-9-]*$",
|
||||
"errorMessage": "Value can contain only latin letters, numbers and hyphen and should start with a letter"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"addToOutput": "*"
|
||||
},
|
||||
"##publish": {
|
||||
"type": "Map",
|
||||
"required": true,
|
||||
"isHidden": true,
|
||||
"configurable": false,
|
||||
"defaultValue":{
|
||||
"name": {
|
||||
"@CALCULATED": {
|
||||
"expression": "${objectId}",
|
||||
"lazy": true
|
||||
}
|
||||
},
|
||||
"factory": {
|
||||
"@CALCULATED": {
|
||||
"expression": "${factoryId}",
|
||||
"lazy": false
|
||||
}
|
||||
},
|
||||
"label": {
|
||||
"@CALCULATED": {
|
||||
"expression": "${#FACTORY#.factory.label}",
|
||||
"lazy": false
|
||||
}
|
||||
},
|
||||
"scope": {
|
||||
"@CALCULATED": {
|
||||
"expression": "${scope}",
|
||||
"allowObjects": false,
|
||||
"lazy": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"objectId": {
|
||||
"displayName": "Object Id",
|
||||
"type": "String",
|
||||
"description": "ID for Entaxy entity",
|
||||
"required": true,
|
||||
"immutable": true,
|
||||
"@TYPEINFO": {
|
||||
"validation": {
|
||||
"rules": {
|
||||
"length": {
|
||||
"min": 3
|
||||
},
|
||||
"content": {
|
||||
"regex": "^[a-zA-Z][a-zA-Z0-9-]*$",
|
||||
"errorMessage": "Value can contain only latin letters, numbers and hyphen and should start with a letter"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"addToOutput": "*"
|
||||
},
|
||||
"displayName": {
|
||||
"type": "String",
|
||||
"description": "Name of the Entaxy entity that will be used as an alias for displaying at UI",
|
||||
"displayName": "Display name",
|
||||
"@UI": {
|
||||
"ignoreChildChanges": true
|
||||
}
|
||||
},
|
||||
"description": {
|
||||
"type": "String",
|
||||
"displayName": "Description",
|
||||
"required": false,
|
||||
"isHidden": false,
|
||||
"@TYPEINFO": {
|
||||
"useTextarea": true
|
||||
},
|
||||
"@UI": {
|
||||
"ignoreChildChanges": true
|
||||
}
|
||||
},
|
||||
"##publish": {
|
||||
"type": "Map",
|
||||
"required": true,
|
||||
"isHidden": true,
|
||||
"configurable": false,
|
||||
"@INTERNAL": true,
|
||||
"defaultValue": {
|
||||
"name": {
|
||||
"@CALCULATED": {
|
||||
"expression": "${objectId}",
|
||||
"lazy": true
|
||||
}
|
||||
},
|
||||
"displayName": {
|
||||
"@CALCULATED": {
|
||||
"expression": "${properties.displayName}",
|
||||
"lazy": true,
|
||||
"allowNulls": true,
|
||||
"allowObjects": false,
|
||||
"resultType": "string",
|
||||
"fallbackObject": ""
|
||||
}
|
||||
},
|
||||
"factory": {
|
||||
"@CALCULATED": {
|
||||
"expression": "${factoryId}",
|
||||
"lazy": false
|
||||
}
|
||||
},
|
||||
"label": {
|
||||
"@CALCULATED": {
|
||||
"expression": "${#FACTORY#.factory.label}",
|
||||
"lazy": false
|
||||
}
|
||||
},
|
||||
"scope": {
|
||||
"@CALCULATED": {
|
||||
"expression": "${scope}",
|
||||
"allowObjects": false,
|
||||
"lazy": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": {
|
||||
"init": {
|
||||
"isDefault": true,
|
||||
"fields": {
|
||||
"##publish": {}
|
||||
"displayName": {},
|
||||
"##publish": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user