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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>objects-core</artifactId>
|
||||
|
@ -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
|
||||
@ -28,126 +28,151 @@ package ru.entaxy.platform.base.objects;
|
||||
import java.util.List;
|
||||
|
||||
public interface EntaxyObject {
|
||||
|
||||
public interface HEADERS {
|
||||
|
||||
String ENTAXY_GENERATED = "Entaxy-Generated";
|
||||
String MAIN_OBJECT = "Entaxy-Main-Object";
|
||||
String GENERATED_OBJECTS = "Entaxy-Generated-Object";
|
||||
// public static final String HEADER_MAIN_OBJECT_ID = "Entaxy-Main-Object-Id";
|
||||
// public static final String HEADER_MAIN_OBJECT_TYPE = "Entaxy-Main-Object-Type";
|
||||
// public static final String HEADER_MAIN_OBJECT_FACTORY_ID = "Entaxy-Main-Object-Factory";
|
||||
// public static final String HEADER_OBJECT_ID = "Entaxy-Generated-Object";
|
||||
// public static final String HEADER_OBJECT_TYPE = "Entaxy-Generated-Object-Type";
|
||||
String GENERATED_OBJECTS_CONFIG = "Entaxy-Generated-Object-Configuration";
|
||||
public interface HEADERS {
|
||||
|
||||
}
|
||||
|
||||
public interface FIELDS {
|
||||
|
||||
public static final String FACTORY_ID = "factoryId";
|
||||
public static final String SCOPE = "scope";
|
||||
|
||||
public static final String OBJECT_ID = "objectId";
|
||||
public static final String OBJECT_TYPE = "type";
|
||||
|
||||
public static final String IS_REF = "isRef";
|
||||
public static final String IS_BACK_REF = "isBackRef";
|
||||
public static final String IS_REF_BY_VALUE_ONLY = "isRefByValueOnly";
|
||||
public static final String REF_FIELD = "refField";
|
||||
|
||||
public static final String DEFAULT_VALUE = "defaultValue";
|
||||
|
||||
public static final String PROPERTIES = "properties";
|
||||
String ENTAXY_GENERATED = "Entaxy-Generated";
|
||||
String MAIN_OBJECT = "Entaxy-Main-Object";
|
||||
String GENERATED_OBJECTS = "Entaxy-Generated-Object";
|
||||
// public static final String HEADER_MAIN_OBJECT_ID = "Entaxy-Main-Object-Id";
|
||||
// public static final String HEADER_MAIN_OBJECT_TYPE = "Entaxy-Main-Object-Type";
|
||||
// public static final String HEADER_MAIN_OBJECT_FACTORY_ID = "Entaxy-Main-Object-Factory";
|
||||
// public static final String HEADER_OBJECT_ID = "Entaxy-Generated-Object";
|
||||
// public static final String HEADER_OBJECT_TYPE = "Entaxy-Generated-Object-Type";
|
||||
String GENERATED_OBJECTS_CONFIG = "Entaxy-Generated-Object-Configuration";
|
||||
|
||||
public static final String FIELDS_TO_PUBLISH = "##publish";
|
||||
}
|
||||
|
||||
public interface OBJECT_TYPES {
|
||||
|
||||
public static final String ENTAXY_RUNTIME_TYPE_PREFIX = "entaxy.runtime.";
|
||||
|
||||
public static final String PROFILE = ENTAXY_RUNTIME_TYPE_PREFIX + "profile";
|
||||
public static final String CONNECTOR = ENTAXY_RUNTIME_TYPE_PREFIX + "connector";
|
||||
public static final String CONNECTION = ENTAXY_RUNTIME_TYPE_PREFIX + "connection";
|
||||
public static final String DEFAULT_ROUTE = ENTAXY_RUNTIME_TYPE_PREFIX + "default-route";
|
||||
|
||||
public static boolean isRuntimeType(String typeName) {
|
||||
return (typeName!=null) && typeName.startsWith(ENTAXY_RUNTIME_TYPE_PREFIX);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum OBJECT_RELATION {
|
||||
ASSOCIATION,
|
||||
AGGREGATION,
|
||||
COMPOSITION,
|
||||
DEPENDENCY,
|
||||
USE
|
||||
}
|
||||
}
|
||||
|
||||
public enum OBJECT_RELATION_SCOPE {
|
||||
RUNTIME,
|
||||
DESIGN
|
||||
}
|
||||
|
||||
public interface RelationDescriptor {
|
||||
OBJECT_RELATION getType();
|
||||
String getName();
|
||||
String getGroup();
|
||||
|
||||
OBJECT_RELATION_SCOPE getScope();
|
||||
|
||||
default boolean isSubordinating() {
|
||||
return OBJECT_RELATION.AGGREGATION.equals(getType())
|
||||
|| OBJECT_RELATION.COMPOSITION.equals(getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface Relation extends RelationDescriptor {
|
||||
|
||||
EntaxyObject getSource();
|
||||
EntaxyObject getTarget();
|
||||
|
||||
boolean isDefinedInSource();
|
||||
|
||||
}
|
||||
|
||||
public interface CAPABILITIES {
|
||||
String ATTR_RELATION = "relation";
|
||||
}
|
||||
|
||||
public static interface BundleInfo {
|
||||
public long getBundleId();
|
||||
}
|
||||
|
||||
public String getId();
|
||||
public String getType();
|
||||
@Deprecated
|
||||
public default String getObjectId() {
|
||||
return getId();
|
||||
};
|
||||
@Deprecated
|
||||
public default String getObjectType() {
|
||||
return getType();
|
||||
};
|
||||
|
||||
public default String getObjectFullId() {
|
||||
return getId() + ":" + getType();
|
||||
};
|
||||
|
||||
public String getScope();
|
||||
|
||||
public String getFactoryId();
|
||||
public BundleInfo getBundleInfo();
|
||||
public String getConfiguration();
|
||||
|
||||
public boolean isProvided();
|
||||
public boolean isComplete();
|
||||
|
||||
public boolean isGhost();
|
||||
|
||||
public List<Relation> getRelations();
|
||||
public List<Relation> getIncomingRelations();
|
||||
public interface FIELDS {
|
||||
|
||||
public static final String FACTORY_ID = "factoryId";
|
||||
public static final String SCOPE = "scope";
|
||||
|
||||
public static final String OBJECT_ID = "objectId";
|
||||
public static final String OBJECT_TYPE = "type";
|
||||
|
||||
public static final String IS_REF = "isRef";
|
||||
public static final String IS_BACK_REF = "isBackRef";
|
||||
public static final String IS_REF_BY_VALUE_ONLY = "isRefByValueOnly";
|
||||
public static final String REF_FIELD = "refField";
|
||||
|
||||
public static final String DEFAULT_VALUE = "defaultValue";
|
||||
|
||||
public static final String PROPERTIES = "properties";
|
||||
|
||||
public static final String FIELDS_TO_PUBLISH = "##publish";
|
||||
}
|
||||
|
||||
public interface OBJECT_TYPES {
|
||||
|
||||
public static final String ENTAXY_RUNTIME_TYPE_PREFIX = "entaxy.runtime.";
|
||||
|
||||
public static final String PROFILE = ENTAXY_RUNTIME_TYPE_PREFIX + "profile";
|
||||
public static final String CONNECTOR = ENTAXY_RUNTIME_TYPE_PREFIX + "connector";
|
||||
public static final String CONNECTION = ENTAXY_RUNTIME_TYPE_PREFIX + "connection";
|
||||
public static final String DEFAULT_ROUTE = ENTAXY_RUNTIME_TYPE_PREFIX + "default-route";
|
||||
|
||||
public static boolean isRuntimeType(String typeName) {
|
||||
return (typeName != null) && typeName.startsWith(ENTAXY_RUNTIME_TYPE_PREFIX);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum OBJECT_RELATION {
|
||||
ASSOCIATION,
|
||||
AGGREGATION,
|
||||
COMPOSITION,
|
||||
DEPENDENCY,
|
||||
USE
|
||||
}
|
||||
|
||||
public interface OBJECT_SCOPE {
|
||||
|
||||
String PRIVATE = "private";
|
||||
String PROTECTED = "protected";
|
||||
String PUBLIC = "public";
|
||||
|
||||
}
|
||||
|
||||
public enum OBJECT_RELATION_SCOPE {
|
||||
RUNTIME,
|
||||
DESIGN
|
||||
}
|
||||
|
||||
public interface RelationDescriptor {
|
||||
OBJECT_RELATION getType();
|
||||
|
||||
String getName();
|
||||
|
||||
String getGroup();
|
||||
|
||||
OBJECT_RELATION_SCOPE getScope();
|
||||
|
||||
default boolean isSubordinating() {
|
||||
return OBJECT_RELATION.AGGREGATION.equals(getType())
|
||||
|| OBJECT_RELATION.COMPOSITION.equals(getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface Relation extends RelationDescriptor {
|
||||
|
||||
EntaxyObject getSource();
|
||||
|
||||
EntaxyObject getTarget();
|
||||
|
||||
boolean isDefinedInSource();
|
||||
|
||||
}
|
||||
|
||||
public interface CAPABILITIES {
|
||||
String ATTR_DISPLAY_NAME = "displayName";
|
||||
String ATTR_RELATION = "relation";
|
||||
String ATTR_SCOPE = "scope";
|
||||
String ATTR_OWNER = "owner";
|
||||
}
|
||||
|
||||
public static interface BundleInfo {
|
||||
public long getBundleId();
|
||||
}
|
||||
|
||||
public String getId();
|
||||
|
||||
public String getType();
|
||||
|
||||
@Deprecated
|
||||
public default String getObjectId() {
|
||||
return getId();
|
||||
};
|
||||
|
||||
@Deprecated
|
||||
public default String getObjectType() {
|
||||
return getType();
|
||||
};
|
||||
|
||||
public default String getObjectFullId() {
|
||||
return getId() + ":" + getType();
|
||||
};
|
||||
|
||||
public String getDisplayName();
|
||||
|
||||
public String getScope();
|
||||
|
||||
public String getOwner();
|
||||
|
||||
public String getFactoryId();
|
||||
|
||||
public BundleInfo getBundleInfo();
|
||||
|
||||
public String getConfiguration();
|
||||
|
||||
public boolean isProvided();
|
||||
|
||||
public boolean isComplete();
|
||||
|
||||
public boolean isGhost();
|
||||
|
||||
public List<Relation> getRelations();
|
||||
|
||||
public List<Relation> getIncomingRelations();
|
||||
}
|
||||
|
@ -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~~~~~~
|
||||
* objects-core
|
||||
* ==========
|
||||
* 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
|
||||
@ -144,11 +144,13 @@ public class EntaxyObjectServiceImpl implements EntaxyObjectService {
|
||||
synchronized (trackedObjectsLock) {
|
||||
|
||||
boolean isModified = false;
|
||||
TrackedEntaxyObject existing = object;
|
||||
|
||||
String fullId = getFullId(object.getId(), object.getType());
|
||||
if (acquireTrackedObjects().containsKey(fullId)) {
|
||||
// object was created as a placeholder via relations
|
||||
updateObject(acquireTrackedObjects().get(fullId), object);
|
||||
existing = acquireTrackedObjects().get(fullId);
|
||||
isModified = true;
|
||||
} else {
|
||||
// object is new
|
||||
@ -161,10 +163,10 @@ public class EntaxyObjectServiceImpl implements EntaxyObjectService {
|
||||
|
||||
TrackedEntaxyObject relationSource = relationDescriptor.relationInverse
|
||||
?targetByDescriptorObject
|
||||
:object;
|
||||
:existing;
|
||||
|
||||
TrackedEntaxyObject relationTarget = relationDescriptor.relationInverse
|
||||
?object
|
||||
?existing
|
||||
:targetByDescriptorObject;
|
||||
|
||||
relationSource.relation(relationTarget, relationDescriptor);
|
||||
|
@ -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
|
||||
@ -44,376 +44,416 @@ import ru.entaxy.platform.base.support.JSONUtils;
|
||||
|
||||
public class TrackedEntaxyObject implements EntaxyObject {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TrackedEntaxyObject.class);
|
||||
|
||||
static public TrackedEntaxyObject create(BundleContext bundleContext, String objectId, String objectType) {
|
||||
log.debug("\n\t CREATING TrackedEntaxyObject: [{}]:[{}]", objectId, objectType);
|
||||
return new TrackedEntaxyObject(bundleContext, objectId, objectType);
|
||||
}
|
||||
private static final Logger log = LoggerFactory.getLogger(TrackedEntaxyObject.class);
|
||||
|
||||
static public TrackedEntaxyObject create(BundleContext bundleContext, String objectId, String objectType, String scope) {
|
||||
log.debug("\n\t CREATING TrackedEntaxyObject: [{}]:[{}]", objectId, objectType);
|
||||
return new TrackedEntaxyObject(bundleContext, objectId, objectType, scope);
|
||||
}
|
||||
|
||||
protected BundleContext bundleContext;
|
||||
|
||||
protected String objectId;
|
||||
protected String objectType;
|
||||
protected String objectScope = "public";
|
||||
protected String factoryId = "UNKNOWN";
|
||||
|
||||
protected boolean isGhost = false;
|
||||
|
||||
protected JsonObject configuration;
|
||||
|
||||
protected BundleInfoImpl bundleInfoImpl;
|
||||
|
||||
protected boolean isProvided = false;
|
||||
|
||||
protected List<RelationDescriptor> relationDescriptors = new ArrayList<>();
|
||||
|
||||
public static final OBJECT_RELATION DEFAULT_RELATION = OBJECT_RELATION.AGGREGATION;
|
||||
static public TrackedEntaxyObject create(BundleContext bundleContext, String objectId, String objectType) {
|
||||
log.debug("\n\t CREATING TrackedEntaxyObject: [{}]:[{}]", objectId, objectType);
|
||||
return new TrackedEntaxyObject(bundleContext, objectId, objectType);
|
||||
}
|
||||
|
||||
public static final OBJECT_RELATION_SCOPE DEFAULT_RELATION_SCOPE = OBJECT_RELATION_SCOPE.RUNTIME;
|
||||
|
||||
public static final boolean DEFAULT_RELATION_INVERSE = true;
|
||||
|
||||
protected Map<String, ObjectRelation> relations = new LinkedHashMap<>();
|
||||
protected List<Relation> incomingRelations = new ArrayList<>();
|
||||
|
||||
protected TrackedEntaxyObject(BundleContext bundleContext, String objectId, String objectType) {
|
||||
super();
|
||||
this.bundleContext = bundleContext;
|
||||
this.objectId = objectId;
|
||||
this.objectType = objectType;
|
||||
}
|
||||
static public TrackedEntaxyObject create(BundleContext bundleContext, String objectId, String objectType,
|
||||
String scope) {
|
||||
log.debug("\n\t CREATING TrackedEntaxyObject: [{}]:[{}]", objectId, objectType);
|
||||
return new TrackedEntaxyObject(bundleContext, objectId, objectType, scope);
|
||||
}
|
||||
|
||||
protected TrackedEntaxyObject(BundleContext bundleContext, String objectId, String objectType, String scope) {
|
||||
this(bundleContext, objectId, objectType);
|
||||
this.objectScope = scope;
|
||||
}
|
||||
protected BundleContext bundleContext;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.objectId;
|
||||
}
|
||||
protected String objectId;
|
||||
protected String objectType;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return this.objectType;
|
||||
}
|
||||
protected String displayName;
|
||||
|
||||
@Override
|
||||
public String getScope() {
|
||||
return this.objectScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactoryId() {
|
||||
return this.factoryId;
|
||||
}
|
||||
protected String objectScope = EntaxyObject.OBJECT_SCOPE.PUBLIC;
|
||||
|
||||
@Override
|
||||
public BundleInfo getBundleInfo() {
|
||||
return this.bundleInfoImpl;
|
||||
}
|
||||
protected String objectOwner = "";
|
||||
|
||||
@Override
|
||||
public String getConfiguration() {
|
||||
return (this.configuration == null?"{}":this.configuration.toString());
|
||||
}
|
||||
protected String factoryId = "UNKNOWN";
|
||||
|
||||
@Override
|
||||
public List<Relation> getRelations() {
|
||||
return this.relations.values()
|
||||
.stream()
|
||||
.map(r -> (Relation)r)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public TrackedEntaxyObject bundle(Bundle bundleValue) {
|
||||
this.bundleInfoImpl = new BundleInfoImpl(bundleContext, bundleValue.getBundleId());
|
||||
return this;
|
||||
};
|
||||
|
||||
public TrackedEntaxyObject configuration(String configurationValue) {
|
||||
|
||||
try {
|
||||
this.configuration = JSONUtils.getJsonRootObject(configurationValue);
|
||||
if (this.configuration.has(EntaxyObject.FIELDS.FACTORY_ID))
|
||||
this.factoryId = this.configuration.get(EntaxyObject.FIELDS.FACTORY_ID).getAsString();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
if (this.configuration == null)
|
||||
this.configuration = new JsonObject();
|
||||
|
||||
return this;
|
||||
}
|
||||
protected boolean isGhost = false;
|
||||
|
||||
@Override
|
||||
public boolean isProvided() {
|
||||
return isProvided;
|
||||
}
|
||||
protected JsonObject configuration;
|
||||
|
||||
public void setProvided(boolean isProvided) {
|
||||
this.isProvided = isProvided;
|
||||
};
|
||||
protected BundleInfoImpl bundleInfoImpl;
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return (this.bundleContext != null) && (this.configuration != null);
|
||||
}
|
||||
|
||||
public void relation(TrackedEntaxyObject target, RelationDescriptor descriptor) {
|
||||
ObjectRelation rel = new ObjectRelation();
|
||||
rel.source = this;
|
||||
rel.target = target;
|
||||
rel.type = descriptor.relationType;
|
||||
rel.scope = descriptor.relationScope;
|
||||
rel.name = descriptor.relationName;
|
||||
rel.group = descriptor.relationGroup;
|
||||
rel.isDefinedInSource = !descriptor.relationInverse;
|
||||
this.relations.put(rel.getUniqueId(), rel);
|
||||
target.incomingRelation(rel);
|
||||
}
|
||||
|
||||
public void removeRelation(ObjectRelation relation) {
|
||||
this.relations.remove(relation.getUniqueId());
|
||||
}
|
||||
|
||||
public void incomingRelation(Relation relation) {
|
||||
this.incomingRelations.add(relation);
|
||||
}
|
||||
protected boolean isProvided = false;
|
||||
|
||||
public void removeIncomingRelation(Relation relation) {
|
||||
this.incomingRelations.remove(relation);
|
||||
}
|
||||
|
||||
public boolean hasRelations() {
|
||||
return !this.relations.isEmpty() || !this.incomingRelations.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Relation> getIncomingRelations() {
|
||||
return incomingRelations;
|
||||
}
|
||||
protected List<RelationDescriptor> relationDescriptors = new ArrayList<>();
|
||||
|
||||
public void relationDescription(String descriptor) {
|
||||
RelationDescriptor rd = createRelationDescription(descriptor);
|
||||
String message = "\n\tPARSING: ".concat(descriptor).concat("; RESULT: ");
|
||||
if (rd != null) {
|
||||
this.relationDescriptors.add(rd);
|
||||
message = message.concat(rd.toString());
|
||||
} else {
|
||||
message = message.concat("null");
|
||||
}
|
||||
log.debug(message);
|
||||
}
|
||||
|
||||
protected RelationDescriptor createRelationDescription(String descriptor) {
|
||||
String[] parsed = descriptor.split(":");
|
||||
RelationDescriptor rd = new RelationDescriptor();
|
||||
|
||||
if (parsed.length < 2)
|
||||
return null;
|
||||
|
||||
rd.targetId = parsed[0];
|
||||
rd.targetType = parsed[1];
|
||||
|
||||
if (parsed.length < 3)
|
||||
return rd;
|
||||
rd.relationName = CommonUtils.getValid(parsed[2], "relation");
|
||||
|
||||
public static final OBJECT_RELATION DEFAULT_RELATION = OBJECT_RELATION.AGGREGATION;
|
||||
|
||||
if (parsed.length < 4)
|
||||
return rd;
|
||||
if (!parseRelationType(parsed[3], rd)) {
|
||||
// old-style relation descriptor without relation type
|
||||
|
||||
rd.relationType = DEFAULT_RELATION;
|
||||
rd.relationInverse = DEFAULT_RELATION_INVERSE;
|
||||
|
||||
rd.relationGroup = CommonUtils.getValid(parsed[3], "");
|
||||
return rd;
|
||||
}
|
||||
|
||||
if (parsed.length < 5)
|
||||
return rd;
|
||||
rd.relationGroup = CommonUtils.getValid(parsed[4], "");
|
||||
|
||||
return rd;
|
||||
}
|
||||
|
||||
protected boolean parseRelationType(String data, RelationDescriptor rd) {
|
||||
if (!CommonUtils.isValid(data))
|
||||
return false;
|
||||
boolean inverse = data.startsWith("-");
|
||||
String type = inverse?data.substring(1):data;
|
||||
public static final OBJECT_RELATION_SCOPE DEFAULT_RELATION_SCOPE = OBJECT_RELATION_SCOPE.RUNTIME;
|
||||
|
||||
String typeToParse = type;
|
||||
String scopeToParse = "";
|
||||
int ind = type.indexOf("/");
|
||||
if (ind>0) {
|
||||
typeToParse = type.substring(0, ind);
|
||||
scopeToParse = type.substring(ind+1);
|
||||
}
|
||||
|
||||
try {
|
||||
rd.relationType = OBJECT_RELATION.valueOf(typeToParse.toUpperCase());
|
||||
rd.relationInverse = inverse;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
public static final boolean DEFAULT_RELATION_INVERSE = true;
|
||||
|
||||
try {
|
||||
rd.relationScope = OBJECT_RELATION_SCOPE.valueOf(scopeToParse.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
// ignore: use default scope
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<RelationDescriptor> getRelationDescriptors() {
|
||||
return relationDescriptors;
|
||||
}
|
||||
protected Map<String, ObjectRelation> relations = new LinkedHashMap<>();
|
||||
protected List<Relation> incomingRelations = new ArrayList<>();
|
||||
|
||||
public void setRelationDescriptors(List<RelationDescriptor> relationDescriptors) {
|
||||
this.relationDescriptors = relationDescriptors;
|
||||
}
|
||||
|
||||
public void updateFrom(TrackedEntaxyObject newOne) {
|
||||
this.objectScope = newOne.getScope();
|
||||
this.bundleContext = newOne.bundleContext;
|
||||
this.bundle(this.bundleContext.getBundle(newOne.getBundleInfo().getBundleId()));
|
||||
this.configuration = newOne.configuration;
|
||||
this.factoryId = newOne.factoryId;
|
||||
this.setProvided(newOne.isProvided);
|
||||
this.setRelationDescriptors(newOne.getRelationDescriptors());
|
||||
this.relations.putAll(newOne.relations);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.objectScope = "";
|
||||
this.bundleContext = null;
|
||||
this.bundleInfoImpl = null;
|
||||
this.configuration = null;
|
||||
this.factoryId = "";
|
||||
this.setProvided(false);
|
||||
}
|
||||
|
||||
public void makeGhost() {
|
||||
this.isGhost = true;
|
||||
List<String> idsToRemove = new ArrayList<>();
|
||||
|
||||
for (ObjectRelation rel: this.relations.values()) {
|
||||
if (rel.isDefinedInSource())
|
||||
idsToRemove.add(rel.getUniqueId());
|
||||
rel.target.removeIncomingRelation((Relation)rel);
|
||||
}
|
||||
for (String id: idsToRemove)
|
||||
this.relations.remove(id);
|
||||
|
||||
List<Relation> relationsToRemove = new ArrayList<>();
|
||||
for (Relation rel: this.incomingRelations) {
|
||||
if (!rel.isDefinedInSource()) {
|
||||
if (rel instanceof ObjectRelation) {
|
||||
((ObjectRelation)rel).source.removeRelation((ObjectRelation)rel);
|
||||
relationsToRemove.add(rel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Relation rel: relationsToRemove)
|
||||
this.incomingRelations.remove(rel);
|
||||
}
|
||||
protected TrackedEntaxyObject(BundleContext bundleContext, String objectId, String objectType) {
|
||||
super();
|
||||
this.bundleContext = bundleContext;
|
||||
this.objectId = objectId;
|
||||
this.objectType = objectType;
|
||||
}
|
||||
|
||||
public void unmakeGhost() {
|
||||
this.isGhost = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGhost() {
|
||||
return isGhost;
|
||||
}
|
||||
protected TrackedEntaxyObject(BundleContext bundleContext, String objectId, String objectType, String scope) {
|
||||
this(bundleContext, objectId, objectType);
|
||||
this.objectScope = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.objectId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return this.objectType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return CommonUtils.isValid(this.displayName)
|
||||
? this.displayName
|
||||
: getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScope() {
|
||||
return this.objectScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner() {
|
||||
return this.objectOwner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactoryId() {
|
||||
return this.factoryId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BundleInfo getBundleInfo() {
|
||||
return this.bundleInfoImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfiguration() {
|
||||
return (this.configuration == null ? "{}" : this.configuration.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Relation> getRelations() {
|
||||
return this.relations.values()
|
||||
.stream()
|
||||
.map(r -> (Relation) r)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public TrackedEntaxyObject bundle(Bundle bundleValue) {
|
||||
this.bundleInfoImpl = new BundleInfoImpl(bundleContext, bundleValue.getBundleId());
|
||||
return this;
|
||||
};
|
||||
|
||||
public TrackedEntaxyObject configuration(String configurationValue) {
|
||||
|
||||
try {
|
||||
this.configuration = JSONUtils.getJsonRootObject(configurationValue);
|
||||
if (this.configuration.has(EntaxyObject.FIELDS.FACTORY_ID))
|
||||
this.factoryId = this.configuration.get(EntaxyObject.FIELDS.FACTORY_ID).getAsString();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
if (this.configuration == null)
|
||||
this.configuration = new JsonObject();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProvided() {
|
||||
return isProvided;
|
||||
}
|
||||
|
||||
public void setProvided(boolean isProvided) {
|
||||
this.isProvided = isProvided;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return (this.bundleContext != null) && (this.configuration != null);
|
||||
}
|
||||
|
||||
public void relation(TrackedEntaxyObject target, RelationDescriptor descriptor) {
|
||||
ObjectRelation rel = new ObjectRelation();
|
||||
rel.source = this;
|
||||
rel.target = target;
|
||||
rel.type = descriptor.relationType;
|
||||
rel.scope = descriptor.relationScope;
|
||||
rel.name = descriptor.relationName;
|
||||
rel.group = descriptor.relationGroup;
|
||||
rel.isDefinedInSource = !descriptor.relationInverse;
|
||||
this.relations.put(rel.getUniqueId(), rel);
|
||||
target.incomingRelation(rel);
|
||||
}
|
||||
|
||||
public void removeRelation(ObjectRelation relation) {
|
||||
this.relations.remove(relation.getUniqueId());
|
||||
}
|
||||
|
||||
public void incomingRelation(Relation relation) {
|
||||
this.incomingRelations.add(relation);
|
||||
}
|
||||
|
||||
public void removeIncomingRelation(Relation relation) {
|
||||
this.incomingRelations.remove(relation);
|
||||
}
|
||||
|
||||
public boolean hasRelations() {
|
||||
return !this.relations.isEmpty() || !this.incomingRelations.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Relation> getIncomingRelations() {
|
||||
return incomingRelations;
|
||||
}
|
||||
|
||||
public void relationDescription(String descriptor) {
|
||||
RelationDescriptor rd = createRelationDescription(descriptor);
|
||||
String message = "\n\tPARSING: ".concat(descriptor).concat("; RESULT: ");
|
||||
if (rd != null) {
|
||||
this.relationDescriptors.add(rd);
|
||||
message = message.concat(rd.toString());
|
||||
} else {
|
||||
message = message.concat("null");
|
||||
}
|
||||
log.debug(message);
|
||||
}
|
||||
|
||||
protected RelationDescriptor createRelationDescription(String descriptor) {
|
||||
String[] parsed = descriptor.split(":");
|
||||
RelationDescriptor rd = new RelationDescriptor();
|
||||
|
||||
if (parsed.length < 2)
|
||||
return null;
|
||||
|
||||
rd.targetId = parsed[0];
|
||||
rd.targetType = parsed[1];
|
||||
|
||||
if (parsed.length < 3)
|
||||
return rd;
|
||||
rd.relationName = CommonUtils.getValid(parsed[2], "relation");
|
||||
|
||||
|
||||
protected static class RelationDescriptor {
|
||||
|
||||
String targetId;
|
||||
String targetType;
|
||||
|
||||
String relationName = "relation";
|
||||
OBJECT_RELATION relationType = DEFAULT_RELATION;
|
||||
boolean relationInverse = false;
|
||||
String relationGroup = "";
|
||||
|
||||
OBJECT_RELATION_SCOPE relationScope = DEFAULT_RELATION_SCOPE;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return targetId.concat(":")
|
||||
.concat(targetType).concat(":")
|
||||
.concat(relationName).concat(":")
|
||||
.concat(relationInverse?"-":"")
|
||||
.concat(relationType.name()).concat("/").concat(relationScope.name()).concat(":")
|
||||
.concat(relationGroup);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class ObjectRelation implements Relation {
|
||||
|
||||
TrackedEntaxyObject source;
|
||||
TrackedEntaxyObject target;
|
||||
OBJECT_RELATION type;
|
||||
String name;
|
||||
String group;
|
||||
|
||||
OBJECT_RELATION_SCOPE scope;
|
||||
|
||||
boolean isDefinedInSource = true;
|
||||
|
||||
@Override
|
||||
public EntaxyObject getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyObject getTarget() {
|
||||
return target;
|
||||
}
|
||||
if (parsed.length < 4)
|
||||
return rd;
|
||||
if (!parseRelationType(parsed[3], rd)) {
|
||||
// old-style relation descriptor without relation type
|
||||
|
||||
@Override
|
||||
public OBJECT_RELATION getType() {
|
||||
return type;
|
||||
}
|
||||
rd.relationType = DEFAULT_RELATION;
|
||||
rd.relationInverse = DEFAULT_RELATION_INVERSE;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
rd.relationGroup = CommonUtils.getValid(parsed[3], "");
|
||||
return rd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OBJECT_RELATION_SCOPE getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefinedInSource() {
|
||||
return isDefinedInSource;
|
||||
}
|
||||
|
||||
public String getUniqueId() {
|
||||
return type.name().concat("/").concat(scope.name()).concat(":").concat(name).concat(":").concat(group).concat(":").concat(target.getId());
|
||||
}
|
||||
}
|
||||
if (parsed.length < 5)
|
||||
return rd;
|
||||
rd.relationGroup = CommonUtils.getValid(parsed[4], "");
|
||||
|
||||
return rd;
|
||||
}
|
||||
|
||||
protected boolean parseRelationType(String data, RelationDescriptor rd) {
|
||||
if (!CommonUtils.isValid(data))
|
||||
return false;
|
||||
boolean inverse = data.startsWith("-");
|
||||
String type = inverse ? data.substring(1) : data;
|
||||
|
||||
String typeToParse = type;
|
||||
String scopeToParse = "";
|
||||
int ind = type.indexOf("/");
|
||||
if (ind > 0) {
|
||||
typeToParse = type.substring(0, ind);
|
||||
scopeToParse = type.substring(ind + 1);
|
||||
}
|
||||
|
||||
try {
|
||||
rd.relationType = OBJECT_RELATION.valueOf(typeToParse.toUpperCase());
|
||||
rd.relationInverse = inverse;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
rd.relationScope = OBJECT_RELATION_SCOPE.valueOf(scopeToParse.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
// ignore: use default scope
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<RelationDescriptor> getRelationDescriptors() {
|
||||
return relationDescriptors;
|
||||
}
|
||||
|
||||
public void setRelationDescriptors(List<RelationDescriptor> relationDescriptors) {
|
||||
this.relationDescriptors = relationDescriptors;
|
||||
}
|
||||
|
||||
public void updateFrom(TrackedEntaxyObject newOne) {
|
||||
this.objectScope = newOne.getScope();
|
||||
this.objectOwner = newOne.getOwner();
|
||||
this.bundleContext = newOne.bundleContext;
|
||||
this.bundle(this.bundleContext.getBundle(newOne.getBundleInfo().getBundleId()));
|
||||
this.configuration = newOne.configuration;
|
||||
this.factoryId = newOne.factoryId;
|
||||
this.displayName = newOne.displayName;
|
||||
this.setProvided(newOne.isProvided);
|
||||
this.setRelationDescriptors(newOne.getRelationDescriptors());
|
||||
this.relations.putAll(newOne.relations);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.objectScope = "";
|
||||
this.objectOwner = "";
|
||||
this.displayName = null;
|
||||
this.bundleContext = null;
|
||||
this.bundleInfoImpl = null;
|
||||
this.configuration = null;
|
||||
this.factoryId = "";
|
||||
this.setProvided(false);
|
||||
}
|
||||
|
||||
public void makeGhost() {
|
||||
this.isGhost = true;
|
||||
List<String> idsToRemove = new ArrayList<>();
|
||||
|
||||
for (ObjectRelation rel : this.relations.values()) {
|
||||
if (rel.isDefinedInSource()) {
|
||||
idsToRemove.add(rel.getUniqueId());
|
||||
rel.target.removeIncomingRelation((Relation) rel);
|
||||
}
|
||||
}
|
||||
for (String id : idsToRemove)
|
||||
this.relations.remove(id);
|
||||
|
||||
List<Relation> relationsToRemove = new ArrayList<>();
|
||||
for (Relation rel : this.incomingRelations) {
|
||||
if (!rel.isDefinedInSource()) {
|
||||
if (rel instanceof ObjectRelation) {
|
||||
((ObjectRelation) rel).source.removeRelation((ObjectRelation) rel);
|
||||
relationsToRemove.add(rel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Relation rel : relationsToRemove)
|
||||
this.incomingRelations.remove(rel);
|
||||
}
|
||||
|
||||
public void unmakeGhost() {
|
||||
this.isGhost = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGhost() {
|
||||
return isGhost;
|
||||
}
|
||||
|
||||
public TrackedEntaxyObject scope(String scope) {
|
||||
this.objectScope = scope;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackedEntaxyObject owner(String owner) {
|
||||
this.objectOwner = owner;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackedEntaxyObject displayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
protected static class RelationDescriptor {
|
||||
|
||||
String targetId;
|
||||
String targetType;
|
||||
|
||||
String relationName = "relation";
|
||||
OBJECT_RELATION relationType = DEFAULT_RELATION;
|
||||
boolean relationInverse = false;
|
||||
String relationGroup = "";
|
||||
|
||||
OBJECT_RELATION_SCOPE relationScope = DEFAULT_RELATION_SCOPE;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return targetId.concat(":")
|
||||
.concat(targetType).concat(":")
|
||||
.concat(relationName).concat(":")
|
||||
.concat(relationInverse ? "-" : "")
|
||||
.concat(relationType.name()).concat("/").concat(relationScope.name()).concat(":")
|
||||
.concat(relationGroup);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class ObjectRelation implements Relation {
|
||||
|
||||
TrackedEntaxyObject source;
|
||||
TrackedEntaxyObject target;
|
||||
OBJECT_RELATION type;
|
||||
String name;
|
||||
String group;
|
||||
|
||||
OBJECT_RELATION_SCOPE scope;
|
||||
|
||||
boolean isDefinedInSource = true;
|
||||
|
||||
@Override
|
||||
public EntaxyObject getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyObject getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OBJECT_RELATION getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OBJECT_RELATION_SCOPE getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefinedInSource() {
|
||||
return isDefinedInSource;
|
||||
}
|
||||
|
||||
public String getUniqueId() {
|
||||
return type.name().concat("/").concat(scope.name()).concat(":").concat(name).concat(":").concat(group)
|
||||
.concat(":").concat(target.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -45,85 +45,85 @@ import ru.entaxy.platform.base.support.osgi.tracker.UniformBundleTrackerCustomiz
|
||||
|
||||
public class TrackedEntaxyObjectCustomizer extends UniformBundleTrackerCustomizer<List<TrackedEntaxyObject>> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TrackedEntaxyObjectCustomizer.class);
|
||||
|
||||
protected EntaxyObjectServiceImpl objectServiceImpl;
|
||||
|
||||
public TrackedEntaxyObjectCustomizer(EntaxyObjectServiceImpl objectServiceImpl) {
|
||||
super();
|
||||
this.objectServiceImpl = objectServiceImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TrackedEntaxyObject> createManagedObject(Bundle bundle, BundleEvent event,
|
||||
Map<String, List<?>> filterResults) {
|
||||
|
||||
log.debug("\n\tPROCESS BUNDLE: [{}]; tracker: [{}]", bundle.getBundleId(), this);
|
||||
|
||||
List<TrackedEntaxyObject> result = new ArrayList<>();
|
||||
|
||||
String objectsHeader = bundle.getHeaders().get(EntaxyObject.HEADERS.GENERATED_OBJECTS);
|
||||
String configHeader = bundle.getHeaders().get(EntaxyObject.HEADERS.GENERATED_OBJECTS_CONFIG);
|
||||
|
||||
String[] objects = objectsHeader.split(",");
|
||||
String[] configs = configHeader.split(",");
|
||||
|
||||
BundleCapabilityHelper capabilityHelper = new BundleCapabilityHelper(bundle);
|
||||
|
||||
for (int i=0; i<objects.length; i++) {
|
||||
|
||||
String[] objectData = objects[i].split(":");
|
||||
String configuration = configs[i];
|
||||
if (CommonUtils.isValid(configuration)) {
|
||||
byte[] bytes = Base64.getDecoder().decode(configuration);
|
||||
configuration = new String(bytes);
|
||||
} else {
|
||||
configuration = "{}";
|
||||
}
|
||||
|
||||
TrackedEntaxyObject obj;
|
||||
if (objectData.length>2)
|
||||
obj = TrackedEntaxyObject.create(
|
||||
objectServiceImpl.getBundleContext()
|
||||
, objectData[0]
|
||||
, objectData[1]
|
||||
, objectData[2]
|
||||
);
|
||||
else
|
||||
obj = TrackedEntaxyObject.create(
|
||||
objectServiceImpl.getBundleContext(), objectData[0], objectData[1]
|
||||
);
|
||||
|
||||
CapabilityDescriptor capability = capabilityHelper.findObjectDeclaration(objectData[0], objectData[1]);
|
||||
if (capability != null) {
|
||||
obj.setProvided(true);
|
||||
Object relationData = capability.getAttributes().get(EntaxyObject.CAPABILITIES.ATTR_RELATION);
|
||||
if (relationData != null) {
|
||||
if (relationData instanceof List) {
|
||||
List relationList = (List)relationData;
|
||||
for (Object relation: relationList)
|
||||
if (relation != null)
|
||||
obj.relationDescription(relation.toString());
|
||||
} else
|
||||
if (relationData instanceof String)
|
||||
obj.relationDescription((String)relationData);
|
||||
}
|
||||
}
|
||||
|
||||
obj.bundle(bundle).configuration(configuration);
|
||||
result.add(obj);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public List<TrackedEntaxyObject> addingBundle(Bundle bundle, BundleEvent event) {
|
||||
if (listener != null) {
|
||||
synchronized (listener) {
|
||||
return super.addingBundle(bundle, event);
|
||||
}
|
||||
}
|
||||
return super.addingBundle(bundle, event);
|
||||
}
|
||||
private static final Logger log = LoggerFactory.getLogger(TrackedEntaxyObjectCustomizer.class);
|
||||
|
||||
protected EntaxyObjectServiceImpl objectServiceImpl;
|
||||
|
||||
public TrackedEntaxyObjectCustomizer(EntaxyObjectServiceImpl objectServiceImpl) {
|
||||
super();
|
||||
this.objectServiceImpl = objectServiceImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TrackedEntaxyObject> createManagedObject(Bundle bundle, BundleEvent event,
|
||||
Map<String, List<?>> filterResults) {
|
||||
|
||||
log.debug("\n\tPROCESS BUNDLE: [{}]; tracker: [{}]", bundle.getBundleId(), this);
|
||||
|
||||
List<TrackedEntaxyObject> result = new ArrayList<>();
|
||||
|
||||
String objectsHeader = bundle.getHeaders().get(EntaxyObject.HEADERS.GENERATED_OBJECTS);
|
||||
String configHeader = bundle.getHeaders().get(EntaxyObject.HEADERS.GENERATED_OBJECTS_CONFIG);
|
||||
|
||||
String[] objects = objectsHeader.split(",");
|
||||
String[] configs = configHeader.split(",");
|
||||
|
||||
BundleCapabilityHelper capabilityHelper = new BundleCapabilityHelper(bundle);
|
||||
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
|
||||
String[] objectData = objects[i].split(":");
|
||||
String configuration = configs[i];
|
||||
if (CommonUtils.isValid(configuration)) {
|
||||
byte[] bytes = Base64.getDecoder().decode(configuration);
|
||||
configuration = new String(bytes);
|
||||
} else {
|
||||
configuration = "{}";
|
||||
}
|
||||
|
||||
String scope = EntaxyObject.OBJECT_SCOPE.PUBLIC;
|
||||
|
||||
TrackedEntaxyObject obj;
|
||||
if (objectData.length > 2)
|
||||
scope = objectData[2];
|
||||
obj = TrackedEntaxyObject.create(
|
||||
objectServiceImpl.getBundleContext(), objectData[0], objectData[1], scope);
|
||||
|
||||
CapabilityDescriptor capability = capabilityHelper.findObjectDeclaration(objectData[0], objectData[1]);
|
||||
if (capability != null) {
|
||||
obj.setProvided(true);
|
||||
obj.displayName(capability.getAttributes().getOrDefault(EntaxyObject.CAPABILITIES.ATTR_DISPLAY_NAME, "")
|
||||
.toString());
|
||||
obj.owner(capability.getAttributes().getOrDefault(EntaxyObject.CAPABILITIES.ATTR_OWNER, "")
|
||||
.toString());
|
||||
obj.scope(capability.getAttributes().getOrDefault(EntaxyObject.CAPABILITIES.ATTR_SCOPE, scope)
|
||||
.toString());
|
||||
Object relationData = capability.getAttributes().get(EntaxyObject.CAPABILITIES.ATTR_RELATION);
|
||||
if (relationData != null) {
|
||||
if (relationData instanceof List) {
|
||||
List relationList = (List) relationData;
|
||||
for (Object relation : relationList)
|
||||
if (relation != null)
|
||||
obj.relationDescription(relation.toString());
|
||||
} else if (relationData instanceof String)
|
||||
obj.relationDescription((String) relationData);
|
||||
}
|
||||
}
|
||||
|
||||
obj.bundle(bundle).configuration(configuration);
|
||||
result.add(obj);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public List<TrackedEntaxyObject> addingBundle(Bundle bundle, BundleEvent event) {
|
||||
if (listener != null) {
|
||||
synchronized (listener) {
|
||||
return super.addingBundle(bundle, event);
|
||||
}
|
||||
}
|
||||
return super.addingBundle(bundle, event);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -43,130 +43,144 @@ import ru.entaxy.platform.base.objects.shell.SimpleObjectTree.SimpleObjectTreeNo
|
||||
@Command(name = "object-list", scope = EntaxyObjectServiceSupport.OBJECTS_SCOPE)
|
||||
public class ListObjects extends EntaxyObjectServiceSupport implements Action {
|
||||
|
||||
@Option(name = "-t", aliases = {"--tree"}, description = "Display factory tree")
|
||||
boolean asTree;
|
||||
|
||||
@Override
|
||||
public Object execute() throws Exception {
|
||||
|
||||
ShellTable shellTable = new ShellTable();
|
||||
shellTable.column("Id");
|
||||
shellTable.column("Type");
|
||||
shellTable.column("Provided");
|
||||
shellTable.column("Complete");
|
||||
shellTable.column("Scope");
|
||||
shellTable.column("Full Id");
|
||||
shellTable.column("Factory");
|
||||
shellTable.column("Bundle");
|
||||
|
||||
if (!asTree) {
|
||||
|
||||
for (EntaxyObject object: objectService.getObjects())
|
||||
shellTable.addRow().addContent(
|
||||
(object.isGhost()
|
||||
?"? "
|
||||
:""
|
||||
) + object.getId(),
|
||||
object.getType(),
|
||||
(object.isProvided()?"*":""),
|
||||
(object.isComplete()?"*":""),
|
||||
object.getScope(),
|
||||
object.getObjectFullId(),
|
||||
object.getFactoryId(),
|
||||
object.getBundleInfo()==null
|
||||
?""
|
||||
:object.getBundleInfo().getBundleId()
|
||||
);
|
||||
} else {
|
||||
SimpleObjectTree<EntaxyObject> tree = new SimpleObjectTree<>(new EntaxyObjectHelper());
|
||||
tree.load(objectService.getObjects());
|
||||
for (SimpleObjectTreeNode<EntaxyObject> node: tree.root.children)
|
||||
addRowToTable(shellTable, node);
|
||||
}
|
||||
|
||||
|
||||
shellTable.print(System.out);
|
||||
|
||||
return null;
|
||||
}
|
||||
@Option(name = "-t", aliases = {"--tree"}, description = "Display factory tree")
|
||||
boolean asTree;
|
||||
|
||||
protected String getLevelPrefix(SimpleObjectTreeNode<EntaxyObject> node) {
|
||||
String result = "";
|
||||
for (int i=0; i<node.getLevel()-1; i++)
|
||||
result = result.concat(" ");
|
||||
return result;
|
||||
}
|
||||
@Option(name = "-f", aliases = {"--show-full-id"}, description = "Show full Id")
|
||||
boolean showFullId = false;
|
||||
|
||||
protected void addRowToTable(ShellTable table, SimpleObjectTreeNode<EntaxyObject> node) {
|
||||
if (node.getObject() == null) {
|
||||
table.addRow().addContent(
|
||||
getLevelPrefix(node) + node.getId().split(":")[0]
|
||||
, getLevelPrefix(node) + node.getId().split(":")[1]
|
||||
, ""
|
||||
, ""
|
||||
, ""
|
||||
, node.getId()
|
||||
, ""
|
||||
, ""
|
||||
);
|
||||
|
||||
} else {
|
||||
EntaxyObject object = node.getObject();
|
||||
table.addRow().addContent(
|
||||
getLevelPrefix(node) + (object.isGhost()
|
||||
?"? "
|
||||
:""
|
||||
) + object.getId()
|
||||
, object.getType()
|
||||
, booleanToString(object.isProvided())
|
||||
, booleanToString(object.isComplete())
|
||||
, object.getScope()
|
||||
, object.getObjectFullId()
|
||||
, object.getFactoryId()
|
||||
, (object.isGhost()?"":object.getBundleInfo().getBundleId())
|
||||
);
|
||||
}
|
||||
for (SimpleObjectTreeNode<EntaxyObject> child: node.children) {
|
||||
addRowToTable(table, child);
|
||||
}
|
||||
}
|
||||
|
||||
protected String booleanToString(boolean b) {
|
||||
return b?"*":"";
|
||||
}
|
||||
|
||||
protected class EntaxyObjectHelper extends SimpleObjectTreeHelperCommon<EntaxyObject> {
|
||||
|
||||
@Override
|
||||
public String getId(EntaxyObject object) {
|
||||
return object.getObjectFullId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentId(EntaxyObject object) {
|
||||
final String fullId = object.getObjectFullId();
|
||||
List<EntaxyObject.Relation> candidates = objectService.getObjects()
|
||||
.stream()
|
||||
.filter(obj -> !obj.getRelations().isEmpty())
|
||||
.map(obj -> obj.getRelations())
|
||||
.flatMap(List :: stream)
|
||||
.filter(r -> r.isSubordinating())
|
||||
.filter(r -> fullId.equals(r.getTarget().getObjectFullId()))
|
||||
.collect(Collectors.toList());
|
||||
if (candidates.isEmpty())
|
||||
return null;
|
||||
EntaxyObject parent = null;
|
||||
for (EntaxyObject.Relation relation: candidates)
|
||||
if (relation.getType().equals(OBJECT_RELATION.COMPOSITION)) {
|
||||
parent = relation.getSource();
|
||||
break;
|
||||
}
|
||||
@Override
|
||||
public Object execute() throws Exception {
|
||||
|
||||
ShellTable shellTable = new ShellTable();
|
||||
shellTable.column("Id");
|
||||
shellTable.column("Type");
|
||||
shellTable.column("Provided");
|
||||
shellTable.column("Complete");
|
||||
shellTable.column("Scope");
|
||||
if (showFullId)
|
||||
shellTable.column("Full Id");
|
||||
shellTable.column("Factory");
|
||||
shellTable.column("Bundle");
|
||||
|
||||
if (!asTree) {
|
||||
|
||||
for (EntaxyObject object : objectService.getObjects())
|
||||
if (showFullId) {
|
||||
shellTable.addRow().addContent(
|
||||
(object.isGhost()
|
||||
? "? "
|
||||
: "") + object.getId(),
|
||||
object.getType(),
|
||||
(object.isProvided() ? "*" : ""),
|
||||
(object.isComplete() ? "*" : ""),
|
||||
object.getScope(),
|
||||
object.getObjectFullId(),
|
||||
object.getFactoryId(),
|
||||
object.getBundleInfo() == null
|
||||
? ""
|
||||
: object.getBundleInfo().getBundleId());
|
||||
} else {
|
||||
shellTable.addRow().addContent(
|
||||
(object.isGhost()
|
||||
? "? "
|
||||
: "") + object.getId(),
|
||||
object.getType(),
|
||||
(object.isProvided() ? "*" : ""),
|
||||
(object.isComplete() ? "*" : ""),
|
||||
object.getScope(),
|
||||
object.getFactoryId(),
|
||||
object.getBundleInfo() == null
|
||||
? ""
|
||||
: object.getBundleInfo().getBundleId());
|
||||
}
|
||||
} else {
|
||||
SimpleObjectTree<EntaxyObject> tree = new SimpleObjectTree<>(new EntaxyObjectHelper());
|
||||
tree.load(objectService.getObjects());
|
||||
for (SimpleObjectTreeNode<EntaxyObject> node : tree.root.children)
|
||||
addRowToTable(shellTable, node);
|
||||
}
|
||||
|
||||
|
||||
shellTable.print(System.out);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getLevelPrefix(SimpleObjectTreeNode<EntaxyObject> node) {
|
||||
String result = "";
|
||||
for (int i = 0; i < node.getLevel() - 1; i++)
|
||||
result = result.concat(" ");
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void addRowToTable(ShellTable table, SimpleObjectTreeNode<EntaxyObject> node) {
|
||||
if (node.getObject() == null) {
|
||||
table.addRow().addContent(
|
||||
getLevelPrefix(node) + node.getId().split(":")[0],
|
||||
getLevelPrefix(node) + node.getId().split(":")[1], "", "", "", node.getId(), "", "");
|
||||
|
||||
} else {
|
||||
EntaxyObject object = node.getObject();
|
||||
if (showFullId) {
|
||||
table.addRow().addContent(
|
||||
getLevelPrefix(node) + (object.isGhost()
|
||||
? "? "
|
||||
: "") + object.getId(),
|
||||
object.getType(), booleanToString(object.isProvided()), booleanToString(object.isComplete()),
|
||||
object.getScope(), object.getObjectFullId(), object.getFactoryId(),
|
||||
(object.isGhost() ? "" : object.getBundleInfo().getBundleId()));
|
||||
} else {
|
||||
table.addRow().addContent(
|
||||
getLevelPrefix(node) + (object.isGhost()
|
||||
? "? "
|
||||
: "") + object.getId(),
|
||||
object.getType(), booleanToString(object.isProvided()), booleanToString(object.isComplete()),
|
||||
object.getScope(), object.getFactoryId(),
|
||||
(object.isGhost() ? "" : object.getBundleInfo().getBundleId()));
|
||||
}
|
||||
}
|
||||
for (SimpleObjectTreeNode<EntaxyObject> child : node.children) {
|
||||
addRowToTable(table, child);
|
||||
}
|
||||
}
|
||||
|
||||
protected String booleanToString(boolean b) {
|
||||
return b ? "*" : "";
|
||||
}
|
||||
|
||||
protected class EntaxyObjectHelper extends SimpleObjectTreeHelperCommon<EntaxyObject> {
|
||||
|
||||
@Override
|
||||
public String getId(EntaxyObject object) {
|
||||
return object.getObjectFullId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentId(EntaxyObject object) {
|
||||
final String fullId = object.getObjectFullId();
|
||||
List<EntaxyObject.Relation> candidates = objectService.getObjects()
|
||||
.stream()
|
||||
.filter(obj -> !obj.getRelations().isEmpty())
|
||||
.map(obj -> obj.getRelations())
|
||||
.flatMap(List::stream)
|
||||
.filter(r -> r.isSubordinating())
|
||||
.filter(r -> fullId.equals(r.getTarget().getObjectFullId()))
|
||||
.collect(Collectors.toList());
|
||||
if (candidates.isEmpty())
|
||||
return null;
|
||||
EntaxyObject parent = null;
|
||||
for (EntaxyObject.Relation relation : candidates)
|
||||
if (relation.getType().equals(OBJECT_RELATION.COMPOSITION)) {
|
||||
parent = relation.getSource();
|
||||
break;
|
||||
}
|
||||
|
||||
parent = candidates.get(0).getSource();
|
||||
|
||||
return parent.getObjectFullId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
parent = candidates.get(0).getSource();
|
||||
|
||||
return parent.getObjectFullId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
@ -35,30 +35,41 @@ import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
@Command(name = "object-relations", scope = EntaxyObjectServiceSupport.OBJECTS_SCOPE)
|
||||
public class ObjectRelations extends ObjectAwareCommand {
|
||||
|
||||
@Override
|
||||
public Object doExecute() throws Exception {
|
||||
|
||||
ShellTable shellTable = new ShellTable();
|
||||
shellTable.column("Name");
|
||||
shellTable.column("Type");
|
||||
shellTable.column("Scope");
|
||||
shellTable.column("Target");
|
||||
shellTable.column("Subord");
|
||||
shellTable.column("Group");
|
||||
|
||||
for (EntaxyObject.Relation relation: entaxyObject.getRelations())
|
||||
shellTable.addRow().addContent(
|
||||
relation.getName(),
|
||||
relation.getType().name(),
|
||||
relation.getScope().name(),
|
||||
relation.getTarget().getObjectFullId(),
|
||||
(relation.isSubordinating()?"*":""),
|
||||
relation.getGroup()
|
||||
);
|
||||
|
||||
shellTable.print(System.out);
|
||||
@Override
|
||||
public Object doExecute() throws Exception {
|
||||
|
||||
return null;
|
||||
}
|
||||
ShellTable shellTable = new ShellTable();
|
||||
shellTable.column("Name");
|
||||
shellTable.column("Direction");
|
||||
shellTable.column("Type");
|
||||
shellTable.column("Scope");
|
||||
shellTable.column("Target/Source");
|
||||
shellTable.column("Subord");
|
||||
shellTable.column("Group");
|
||||
|
||||
for (EntaxyObject.Relation relation : entaxyObject.getRelations())
|
||||
shellTable.addRow().addContent(
|
||||
relation.getName(),
|
||||
"outgoing ->",
|
||||
relation.getType().name(),
|
||||
relation.getScope().name(),
|
||||
relation.getTarget().getObjectFullId(),
|
||||
(relation.isSubordinating() ? "*" : ""),
|
||||
relation.getGroup());
|
||||
|
||||
for (EntaxyObject.Relation relation : entaxyObject.getIncomingRelations())
|
||||
shellTable.addRow().addContent(
|
||||
relation.getName(),
|
||||
"incoming <-",
|
||||
relation.getType().name(),
|
||||
relation.getScope().name(),
|
||||
relation.getSource().getObjectFullId(),
|
||||
(relation.isSubordinating() ? "*" : ""),
|
||||
relation.getGroup());
|
||||
|
||||
shellTable.print(System.out);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* objects-core
|
||||
* ==========
|
||||
* 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
|
||||
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime</groupId>
|
||||
<artifactId>base</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<version>1.10.0</version>
|
||||
</parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
|
||||
<artifactId>objects-base</artifactId>
|
||||
|
Reference in New Issue
Block a user