ENTAXY-634 release version 1.9.0

This commit is contained in:
2023-08-11 03:05:45 +03:00
parent 3cc15f7459
commit 574fd61847
1720 changed files with 93209 additions and 44106 deletions

View File

@ -4,21 +4,28 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -121,11 +128,13 @@ public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtend
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";
static Set<String> getAllDirectives(){
return new HashSet<String>() {
@ -139,6 +148,16 @@ public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtend
}};
}
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
@ -174,6 +193,46 @@ public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtend
}
/**
* 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;
}
}
}

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory;
@ -26,12 +32,17 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.DIRECTIVES;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.DIRECTIVES.INHERIT_MODE;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE_MODE;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.FieldInfo;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.OutputInfo;
@ -40,6 +51,8 @@ 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";
@ -273,6 +286,48 @@ public class EntaxyFactoryUtils {
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;
@ -304,6 +359,18 @@ public class EntaxyFactoryUtils {
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());
}
@ -318,6 +385,82 @@ public class EntaxyFactoryUtils {
}
}
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;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.configuration;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.configuration;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.configuration;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.configuration;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.configuration;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.configuration;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.configuration;

View File

@ -0,0 +1,38 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* Copyright (C) 2020 - 2023 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.exceptions;
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryException;
public class FactoryNotFoundException extends EntaxyFactoryException {
private static final long serialVersionUID = 1L;
public FactoryNotFoundException(String factoryId) {
super("Factory [" + factoryId + "] not found");
}
}

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.exceptions;

View File

@ -0,0 +1,45 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* Copyright (C) 2020 - 2023 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.exceptions;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryException;
public class OutputNotDefinedException extends EntaxyFactoryException {
private static final long serialVersionUID = 1L;
private static String getMessage(EntaxyFactory factory, String output) {
return String.format("Output [%s] not defined in factory [%s]"
, output
, factory.getId());
}
public OutputNotDefinedException(EntaxyFactory factory, String output) {
super(getMessage(factory, output));
}
}

View File

@ -0,0 +1,50 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* Copyright (C) 2020 - 2023 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.exceptions;
import java.util.List;
import java.util.stream.Collectors;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryException;
public class ScopeNotSupportedException extends EntaxyFactoryException {
private static final long serialVersionUID = 1L;
private static String getMessage(EntaxyFactory factory, String outputType, String scope, List<String> scopes) {
return String.format("Scope [%s] not supported in factory [%s] for output [%s]; supported scopes are [%s]"
, scope
, factory.getId()
, outputType
, scopes.stream().collect(Collectors.joining(",")));
}
public ScopeNotSupportedException(EntaxyFactory factory, String outputType, String scope, List<String> scopes) {
super(getMessage(factory, outputType, scope, scopes));
}
}

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.impl;
@ -46,6 +52,8 @@ import ru.entaxy.platform.base.objects.factory.configuration.FactoryElement;
import ru.entaxy.platform.base.objects.factory.configuration.FieldsElement;
import ru.entaxy.platform.base.objects.factory.configuration.OutputElement;
import ru.entaxy.platform.base.objects.factory.configuration.OutputsElement;
import ru.entaxy.platform.base.objects.factory.exceptions.OutputNotDefinedException;
import ru.entaxy.platform.base.objects.factory.exceptions.ScopeNotSupportedException;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.JSONUtils;
import ru.entaxy.platform.base.support.osgi.OSGIUtils;
@ -250,7 +258,7 @@ public class DefaultFactory implements EntaxyFactory {
@Override
public Generated generate(String outputType, Map<String, Object> parameters) throws EntaxyFactoryException {
if (!this.outputs.hasOutput(outputType))
throw new EntaxyFactoryException();
throw new OutputNotDefinedException(this, outputType);
return this.generate(outputType, EntaxyFactory.SCOPE.PUBLIC.label, parameters);
}
@ -260,7 +268,7 @@ public class DefaultFactory implements EntaxyFactory {
if (!this.outputs.hasOutput(outputType)) {
log.debug("Factory: {}. Unknown output: {}", this.getId(), outputType);
throw new EntaxyFactoryException();
throw new OutputNotDefinedException(this, outputType);
}
OutputElement oe = this.outputs.getOutput(outputType);
@ -270,7 +278,10 @@ public class DefaultFactory implements EntaxyFactory {
, oe.getType()
, scope
, oe.getSupportedScopes().stream().map(s -> s.label).collect(Collectors.joining(",")));
throw new EntaxyFactoryException();
throw new ScopeNotSupportedException(this
, outputType
, scope
, oe.getSupportedScopes().stream().map(s -> s.label).collect(Collectors.toList()));
}
if (this.getHelper() != null)
@ -279,7 +290,7 @@ public class DefaultFactory implements EntaxyFactory {
} catch (Exception e) {
log.error("Generate failed", e);
// TODO fill the exception
throw new EntaxyFactoryException();
throw new EntaxyFactoryException("Generation failed", e);
}
return null;
}

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.impl;

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.impl;
@ -141,6 +147,10 @@ public class GenerationHelper {
+ candidate + "]");
}
}
log.warn("Template not found for generation; factory={}, output={}, scope={}"
, factory.getId()
, outputType
, scope.label);
return null;
}

View File

@ -0,0 +1,87 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2023 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.tracker;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.JSONUtils;
import ru.entaxy.platform.base.support.osgi.tracker.UniformBundleTrackerCustomizer;
public class TrackedDynamicFactoryCustomizer extends UniformBundleTrackerCustomizer<TrackedFactoryContainer> {
private static final Logger log = LoggerFactory.getLogger(TrackedDynamicFactoryCustomizer.class);
@Override
protected TrackedFactoryContainer createManagedObject(Bundle bundle, BundleEvent event,
Map<String, List<?>> filterResults) {
TrackedFactoryContainer result = new TrackedFactoryContainer(bundle);
String urls = bundle.getHeaders().get(TrackerManager.HEADER_ENTAXY_DYNAMIC_FACTORY_URL);
if (!CommonUtils.isValid(urls))
return result;
String[] factories = urls.split(",");
for (int i=0; i<factories.length; i++) {
String urlString = factories[i];
try {
URL entry = new URL(urlString);
log.debug("Found path: " + urlString);
String id = urlString.substring(urlString.lastIndexOf("/") + 1);
id = id.substring(0, id.lastIndexOf("."));
log.debug("Found id: " + id);
String config = JSONUtils.getJsonRootObjectString(entry);
TrackedFactory tf = new TrackedFactory();
tf.setId(id);
tf.setBundle(bundle);
tf.setConfigString(config);
result.factories.put(id, tf);
} catch (Exception e) {
log.error("Error reading url: " + factories[i], e);
}
}
return result;
}
}

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.tracker;

View File

@ -0,0 +1,94 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* Copyright (C) 2020 - 2023 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.tracker;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.osgi.framework.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.platform.base.support.JSONUtils;
public class TrackedFactoryContainer {
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());
}
}

View File

@ -4,30 +4,32 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.tracker;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
@ -37,19 +39,23 @@ import org.slf4j.LoggerFactory;
import ru.entaxy.platform.base.support.JSONUtils;
import ru.entaxy.platform.base.support.osgi.tracker.UniformBundleTrackerCustomizer;
public class TrackedFactoryCustomizer extends UniformBundleTrackerCustomizer<List<TrackedFactory>> {
public class TrackedFactoryCustomizer extends UniformBundleTrackerCustomizer<TrackedFactoryContainer> {
private static final Logger log = LoggerFactory.getLogger(TrackedFactoryCustomizer.class);
private static final String FACTORY_ROOT_PATH = "/ru/entaxy/factory/";
@Override
protected List<TrackedFactory> createManagedObject(Bundle bundle, BundleEvent event,
protected TrackedFactoryContainer createManagedObject(Bundle bundle, BundleEvent event,
Map<String, List<?>> filterResults) {
TrackedFactoryContainer result = new TrackedFactoryContainer(bundle);
result.reload();
return result;
/*
List<TrackedFactory> result = new ArrayList<>();
Enumeration<URL> entries = bundle.findEntries(FACTORY_ROOT_PATH, "*.json", false);
Enumeration<URL> entries = bundle.findEntries(FACTORY_ROOT_PATH, "*.json", true);
while (entries.hasMoreElements()) {
URL entry = entries.nextElement();
String urlString = entry.toString();
@ -61,12 +67,6 @@ public class TrackedFactoryCustomizer extends UniformBundleTrackerCustomizer<Lis
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);
TrackedFactory tf = new TrackedFactory();
tf.setId(id);
@ -79,6 +79,7 @@ public class TrackedFactoryCustomizer extends UniformBundleTrackerCustomizer<Lis
}
return result;
*/
}

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.tracker;
@ -75,8 +81,6 @@ public class TrackedFactoryCustomizerListener implements BundleTrackerCustomizer
@Override
public void modified(List<TrackedFactory> managedObject) {
// TODO Auto-generated method stub
}
@Override

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.tracker;
@ -47,7 +53,7 @@ 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<List<TrackedFactory>>, FactoryConfigurationStorage {
public class TrackedFactoryManager implements BundleTrackerCustomizerListener<TrackedFactoryContainer>, FactoryConfigurationStorage {
private static final Logger log = LoggerFactory.getLogger(TrackedFactoryManager.class);
@ -63,7 +69,7 @@ public class TrackedFactoryManager implements BundleTrackerCustomizerListener<Li
}
@Override
public void added(List<TrackedFactory> managedObject) {
public void added(TrackedFactoryContainer managedObject) {
if (managedObject == null) {
log.debug("managedObject is null");
return;
@ -73,10 +79,17 @@ public class TrackedFactoryManager implements BundleTrackerCustomizerListener<Li
FactoryProcessor factoryProcessor = new FactoryProcessor();
for (TrackedFactory tf: managedObject) {
for (TrackedFactory tf: managedObject.getFactoryList()) {
log.info("Added factory: " + tf.getId());
TrackedManagedFactory tmf = new TrackedManagedFactory(tf);
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)) {
@ -85,7 +98,12 @@ public class TrackedFactoryManager implements BundleTrackerCustomizerListener<Li
// remove old service
tmf.deactivate();
tmf.reload(tf);
try {
tmf.reload(tf);
} catch (Exception e) {
log.error("Error processing tracked factory: [" + tf.getId() + "]", e);
continue;
}
tmf.detachParent();
@ -154,16 +172,19 @@ public class TrackedFactoryManager implements BundleTrackerCustomizerListener<Li
}
@Override
public void modified(List<TrackedFactory> managedObject) {
// TODO Auto-generated method stub
public void modified(TrackedFactoryContainer managedObject) {
if (managedObject == null)
return;
removed(managedObject);
managedObject.reload();
added(managedObject);
}
@Override
public void removed(List<TrackedFactory> managedObject) {
public void removed(TrackedFactoryContainer managedObject) {
if (managedObject == null)
return;
for (TrackedFactory tf: managedObject) {
for (TrackedFactory tf: managedObject.getFactoryList()) {
try {
tf.getServiceRegistration().unregister();
} catch (Exception e) {
@ -315,7 +336,7 @@ public class TrackedFactoryManager implements BundleTrackerCustomizerListener<Li
// JSON with inheritance & imports resolved
JsonObject jsonEffective;
// JSON with VARIANTS resolved
JsonObject jsonFinal;
public JsonObject jsonFinal;
JsonObject jsonFactorySection = null;
@ -334,18 +355,18 @@ public class TrackedFactoryManager implements BundleTrackerCustomizerListener<Li
public boolean isActive = false;
public TrackedManagedFactory(TrackedFactory factory) {
public TrackedManagedFactory(TrackedFactory factory) throws Exception {
reload(factory);
}
public void reload(TrackedFactory 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.getJsonRootObject(this.trackedFactory.getConfigString());
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))

View File

@ -4,17 +4,23 @@
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
* rights to the Software and any copies are the property of the Copyright Holder. Unless
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
* Software for commercial purposes to provide services to third parties.
*
* http://www.apache.org/licenses/LICENSE-2.0
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
* Under no circumstances does the Copyright Holder guarantee or promise that the
* Software provided by him will be suitable or not suitable for the specific purposes
* of the User, that the Software will meet all commercial and personal subjective
* expectations of the User, that the Software will work properly, without technical
* errors, quickly and uninterruptedly.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
* to the User for any direct or indirect losses of the User, his expenses or actual
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
* or damage to data, property, etc.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.tracker;
@ -41,9 +47,15 @@ public class TrackerManager {
private static final Logger log = LoggerFactory.getLogger(TrackerManager.class);
public static final String HEADER_ENTAXY_FACTORY_PROVIDER = "Entaxy-Factory-Provider";
public static final String HEADER_ENTAXY_DYNAMIC_FACTORY_PROVIDER = "Entaxy-Dynamic-Factory-Provider";
public static final String HEADER_ENTAXY_DYNAMIC_FACTORY_URL = "Entaxy-Dynamic-Factory-Url";
protected BundleContext bundleContext;
protected BundleTracker<List<TrackedFactory>> factoryTracker;
protected BundleTracker<TrackedFactoryContainer> factoryTracker;
protected BundleTracker<TrackedFactoryContainer> dynamicFactoryTracker;
@Reference (cardinality = ReferenceCardinality.MANDATORY)
TrackedFactoryManager factoryManager;
@ -53,18 +65,30 @@ public class TrackerManager {
this.bundleContext = componentContext.getBundleContext();
log.debug("Activated: " + bundleContext.getBundle().getBundleId());
factoryTracker = BundleTrackerUtils.<List<TrackedFactory>>createBuilder()
factoryTracker = BundleTrackerUtils.<TrackedFactoryContainer>createBuilder()
.addFilter(
(new BundleHeaderFilter()).header("Entaxy-Factory-Provider")
(new BundleHeaderFilter()).header(HEADER_ENTAXY_FACTORY_PROVIDER)
)
.customizer(
(new TrackedFactoryCustomizer())
// .listener(new TrackedFactoryCustomizerListener(bundleContext))
.listener(factoryManager)
)
.bundleState(Bundle.ACTIVE | Bundle.INSTALLED | Bundle.RESOLVED)
.bundleState(Bundle.ACTIVE | Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING)
.get();
factoryTracker.open();
dynamicFactoryTracker = BundleTrackerUtils.<TrackedFactoryContainer>createBuilder()
.addFilter(
(new BundleHeaderFilter()).header(HEADER_ENTAXY_DYNAMIC_FACTORY_PROVIDER)
)
.customizer(
(new TrackedDynamicFactoryCustomizer())
// .listener(new TrackedFactoryCustomizerListener(bundleContext))
.listener(factoryManager)
)
.bundleState(Bundle.ACTIVE | Bundle.INSTALLED | Bundle.RESOLVED)
.get();
dynamicFactoryTracker.open();
log.debug("Factory tracker started");
}

View File

@ -2,9 +2,16 @@
"factory": {
"id": "base-object",
"type": "entaxy.runtime.object",
"displayName": "Base abstract object",
"description": "Abstract object",
"isAbstract": true,
"label": "object"
"label": "object",
"@LOCALS": {
"displayName": {
"defaultValue": "",
"required": true
}
}
},
"entaxy.runtime.object": {
"isEntaxyObject": true
@ -15,6 +22,23 @@
"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": {