ENTAXY-480 release version 1.8.3

This commit is contained in:
Валерия Бородина 2023-08-03 04:45:45 +03:00
parent 5844a2e5cf
commit 3cc15f7459
236 changed files with 21106 additions and 0 deletions

View File

@ -0,0 +1,61 @@
[#ftl attributes={"generated.type":"blueprint.fragment"}]
[#--
~~~~~~licensing~~~~~~
file-adapter
==========
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
http://www.apache.org/licenses/LICENSE-2.0
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.
~~~~~~/licensing~~~~~~
--]
<!-- <service interface="org.apache.camel.Component" ref="[=objectId]">
<service-properties>
<entry key="connection.name" value="[=objectId]"/>
</service-properties>
</service> -->
[#if properties??]
[#if properties.ext_createResourceProvider??]
[#if properties.ext_createResourceProvider]
<!-- RESOURCE PROVIDER BEAN -->
<bean id="[=objectId].resourceProvider" class="ru.entaxy.esb.resources.provider.FileResourceProvider">
<property name="protocol" value="[=objectId]" />
<property name="rootDirectory" value="[=properties.rootDirectory]" />
</bean>
<service interface="ru.entaxy.esb.resources.EntaxyResourceProvider" ref="[=objectId].resourceProvider">
<service-properties>
<entry key="connection.name" value="[=objectId]"/>
<entry key="protocol" value="[=objectId]"/>
</service-properties>
</service>
[/#if]
[/#if]
[/#if]
<bean id="[=objectId]" class="ru.entaxy.platform.adapter.file.ExtendedFileComponent">
[#if properties??]
[#list properties as key, value]
[#if !key?starts_with("##") && !key?starts_with("__") && !key?starts_with("ext_")] [#-- we skip additional properties --]
[#if key?starts_with("file_")] [#-- we add parent component properties --]
<property name="[=key[5..]]" value="[=value]"/>
[#else]
<property name="[=key]" value="[=value]"/>
[/#if]
[/#if]
[/#list]
[/#if]
</bean>

View File

@ -0,0 +1,24 @@
[#ftl attributes={"generated.type":"blueprint.fragment"}]
[#--
~~~~~~licensing~~~~~~
file-adapter
==========
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
http://www.apache.org/licenses/LICENSE-2.0
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.
~~~~~~/licensing~~~~~~
--]
<reference id="[=objectId]" interface="org.apache.camel.Component"
filter="(connection.name=[=objectId])"/>

View File

@ -0,0 +1,64 @@
/*-
* ~~~~~~licensing~~~~~~
* generator-api
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.base.generator.template.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.url.AbstractURLStreamHandlerService;
import org.osgi.service.url.URLStreamHandlerService;
import ru.entaxy.base.generator.template.Template;
import ru.entaxy.base.generator.template.TemplateService;
@Component(service = URLStreamHandlerService.class, property = "url.handler.protocol=templates", immediate = true)
public class TemplateServiceURLResolver extends AbstractURLStreamHandlerService {
@Reference(cardinality = ReferenceCardinality.MANDATORY)
TemplateService templateService;
@Override
public URLConnection openConnection(URL url) throws IOException {
String templateId = url.toString();
templateId = templateId.replace("templates:", "");
templateId = templateId.replace("/", ".");
Template template = templateService.getTemplateById(templateId);
if (template == null) {
// we'll try without file extension
int index = templateId.lastIndexOf(".");
if (index>0)
templateId = templateId.substring(0, index);
template = templateService.getTemplateById(templateId);
}
if (template == null)
return null;
String templateUrl = template.getTemplateLocation().toString() + template.getTemplateFullName();
URL resultUrl = new URL(templateUrl);
return resultUrl.openConnection();
}
}

View File

@ -0,0 +1,336 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.DIRECTIVES;
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;
import ru.entaxy.platform.base.objects.factory.Importer.ImportInfo;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.JSONUtils;
public class EntaxyFactoryUtils {
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;
}
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);
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 {
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 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;
}
}

View File

@ -0,0 +1,382 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE_MODE;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.JSONUtils;
public class Importer {
protected JsonObject origin;
protected Map<String, JsonObject> importedSources = new HashMap<>();
public Importer(JsonObject origin) {
this.origin = origin;
}
public List<ImportInfo> findImports(){
return findImports(this.origin);
}
public List<ImportInfo> findImports(JsonObject object) {
List<ImportInfo> result = new ArrayList<>();
if (object.has(EntaxyFactory.CONFIGURATION.DIRECTIVES.IMPORT))
result.add(new ImportInfo(object));
for (Entry<String, JsonElement> entry: object.entrySet())
if (entry.getValue().isJsonObject())
result.addAll(findImports(entry.getValue().getAsJsonObject()));
return result;
}
public void processImports(List<ImportInfo> imports) {
for (ImportInfo ii: imports) {
JsonObject newData = new JsonObject();
for (ImportDescriptor id: ii.importDescriptors) {
JsonObject imported = importedSources.get(id.factoryId);
if (imported == null)
continue;
JsonElement je = JSONUtils.findElement(imported, id.location);
if ((je==null) || !je.isJsonObject())
continue;
Filter f;
if (id.origin.has("filter"))
f = CompositeFilter.create(id.origin.get("filter"));
else
f = new NullFilter();
List<Entry<String, JsonElement>> filteredList = je.getAsJsonObject().entrySet()
.stream()
.filter(e->f.isAccepted(e.getKey(), e.getValue()))
.collect(Collectors.toList());
JsonObject idResult = new JsonObject();
for (Entry<String, JsonElement> entry: filteredList)
idResult.add(id.prefix + entry.getKey(), entry.getValue());
EntaxyFactoryUtils.processObjectOverriding(
newData
, idResult
, OVERRIDE_MODE.UPDATE);
}
JsonObject current = ii.owner.deepCopy();
current.remove(EntaxyFactory.CONFIGURATION.DIRECTIVES.IMPORT);
EntaxyFactoryUtils.processObjectOverriding(newData, current, OVERRIDE_MODE.UPDATE);
Set<String> keys = new HashSet<>(ii.owner.keySet());
for (String key: keys)
ii.owner.remove(key);
for (Entry<String, JsonElement> entry: newData.entrySet())
ii.owner.add(entry.getKey(), entry.getValue());
}
}
// INTERNAL CLASSES
public static abstract class Filter {
public static final String ATTRIBUTE_KEY = "$key";
public static final String ATTRIBUTE_VALUE = "$value";
abstract public boolean isAccepted(String key, JsonElement value);
}
public static class CompositeFilter extends Filter {
List<Filter> filters = new ArrayList<>();
@Override
public boolean isAccepted(String key, JsonElement value) {
for (Filter f: filters)
if (!f.isAccepted(key, value))
return false;
return true;
}
public static Filter create(JsonElement object) {
if (!object.isJsonObject())
return new NullFilter();
final CompositeFilter filter = new CompositeFilter();
if (object.getAsJsonObject().has(ContainsFilter.FILTER_NAME)) {
JsonElement je = object.getAsJsonObject().get(ContainsFilter.FILTER_NAME);
if (je.isJsonArray())
je.getAsJsonArray().forEach(e->filter.filters.add(new ContainsFilter(e)));
}
if (object.getAsJsonObject().has(ContainedFilter.FILTER_NAME)) {
JsonElement je = object.getAsJsonObject().get(ContainedFilter.FILTER_NAME);
if (je.isJsonArray())
je.getAsJsonArray().forEach(e->filter.filters.add(new ContainedFilter(e)));
}
return filter;
}
}
public static class NullFilter extends Filter {
@Override
public boolean isAccepted(String key, JsonElement value) {
return true;
}
}
public static abstract class CommonFilter extends Filter {
String attribute = null;
List<String> values = new ArrayList<>();
boolean isInversed = false;
protected CommonFilter(JsonElement element) {
if (!element.isJsonObject())
return;
JsonObject jo = element.getAsJsonObject();
if (jo.has("inverse"))
this.isInversed = jo.get("inverse").getAsBoolean();
}
@Override
public final boolean isAccepted(String key, JsonElement value) {
if (isInversed)
return !calculateAccepted(key, value);
else
return calculateAccepted(key, value);
}
protected abstract boolean calculateAccepted(String key, JsonElement value);
}
public static class ContainedFilter extends CommonFilter {
public static final String FILTER_NAME = "contained";
public ContainedFilter(JsonElement element) {
super(element);
if (!element.isJsonObject())
return;
JsonObject jo = element.getAsJsonObject();
if (jo.has("attribute"))
this.attribute = jo.get("attribute").getAsString();
if (jo.has("values")) {
if (jo.get("values").isJsonPrimitive())
values.add(jo.get("values").getAsString());
if (jo.get("values").isJsonArray())
jo.get("values").getAsJsonArray().forEach(v->values.add(v.getAsString()));
}
}
@Override
protected boolean calculateAccepted(String key, JsonElement value) {
if (values.isEmpty())
return true;
String testValue = "";
if (ATTRIBUTE_KEY.equals(attribute))
testValue = key;
else if (ATTRIBUTE_VALUE.equals(attribute))
testValue = value.getAsString();
else {
if (value.isJsonObject()) {
JsonObject jo = value.getAsJsonObject();
if (jo.has(attribute))
testValue = jo.get(attribute).getAsString();
}
}
if (!CommonUtils.isValid(testValue))
return false;
return values.contains(testValue);
}
}
public static class ContainsFilter extends CommonFilter {
public static final String FILTER_NAME = "contains";
String separator = ",";
boolean containsAll = false;
public ContainsFilter(JsonElement element) {
super(element);
if (!element.isJsonObject())
return;
JsonObject jo = element.getAsJsonObject();
if (jo.has("attribute"))
this.attribute = jo.get("attribute").getAsString();
if (jo.has("separator"))
this.separator = jo.get("separator").getAsString();
if (jo.has("containsAll"))
this.containsAll = jo.get("containsAll").getAsBoolean();
if (jo.has("values")) {
if (jo.get("values").isJsonPrimitive())
values.add(jo.get("values").getAsString());
if (jo.get("values").isJsonArray())
jo.get("values").getAsJsonArray().forEach(v->values.add(v.getAsString()));
}
}
@Override
protected boolean calculateAccepted(String key, JsonElement value) {
if (values.isEmpty())
return true;
String testValue = "";
List<String> vals = new ArrayList<>();
if (ATTRIBUTE_KEY.equals(attribute))
testValue = key;
else if (ATTRIBUTE_VALUE.equals(attribute))
testValue = value.getAsString();
else {
if (value.isJsonObject()) {
JsonObject jo = value.getAsJsonObject();
if (jo.has(attribute)) {
JsonElement je = jo.get(attribute);
if (je.isJsonPrimitive()) {
testValue = jo.get(attribute).getAsString();
if (!CommonUtils.isValid(testValue))
return false;
String[] arr = testValue.split(separator);
vals = Arrays.asList(arr).stream().map(s->s.trim()).collect(Collectors.toList());
} else if (je.isJsonArray()) {
JsonArray ja = je.getAsJsonArray();
for (int i=0; i<ja.size(); i++) {
if (ja.get(i) == null)
continue;
if (ja.get(i).isJsonPrimitive())
vals.add(ja.get(i).getAsString());
else
vals.add(ja.get(i).toString());
}
}
}
}
}
if (containsAll)
return vals.containsAll(values);
for (String v: values)
if (vals.contains(v))
return true;
return false;
}
}
public static class ImportInfo {
public JsonObject owner;
public JsonElement importElement;
public List<ImportDescriptor> importDescriptors = new ArrayList<>();
public ImportInfo(JsonObject owner) {
List<JsonObject> foundImports = new ArrayList<>();
this.owner = owner;
this.importElement = owner.get(EntaxyFactory.CONFIGURATION.DIRECTIVES.IMPORT);
if (this.importElement.isJsonObject()) {
foundImports.add(this.importElement.getAsJsonObject());
}
if (this.importElement.isJsonArray()) {
JsonArray ja = this.importElement.getAsJsonArray();
for (int i=0; i<ja.size(); i++) {
JsonElement je = ja.get(i);
if (je.isJsonObject())
foundImports.add(je.getAsJsonObject());
}
}
for (JsonObject jo: foundImports)
this.importDescriptors.add(new ImportDescriptor(jo));
}
}
public static class ImportDescriptor {
public String factoryId;
public String location = "";
public String prefix = "";
public JsonObject origin;
public ImportDescriptor (JsonObject origin) {
this.origin = origin;
if (this.origin.has("sourceFactoryId"))
this.factoryId = this.origin.get("sourceFactoryId").getAsString();
if (this.origin.has("location"))
this.location = this.origin.get("location").getAsString();
if (this.origin.has("prefix"))
this.prefix = this.origin.get("prefix").getAsString();
}
}
// S & G
public Map<String, JsonObject> getImportedSources() {
return importedSources;
}
public void addImportedSources(Map<String, JsonObject> importedSources) {
this.importedSources.putAll(importedSources);
}
public void setImportedSources(Map<String, JsonObject> importedSources) {
this.importedSources = importedSources;
}
public JsonObject getOrigin() {
return origin;
}
}

View File

@ -0,0 +1,38 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/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;
@SuppressWarnings("serial")
public class NotSupportedForAbstractFactory extends EntaxyFactoryException {
private static String getMessage(EntaxyFactory factory, String operation) {
return String.format("Factory [%s] is abstract, operation [%s] not supported"
, factory.getId()
, operation);
}
public NotSupportedForAbstractFactory(EntaxyFactory factory, String operation) {
super(getMessage(factory, operation));
}
}

View File

@ -0,0 +1,54 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.impl;
import java.util.HashMap;
import java.util.Map;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
@Component (service = FactoryRegistry.class, immediate = true)
public class FactoryRegistry {
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);
}
}

View File

@ -0,0 +1,448 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.base.objects.factory.tracker;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryUtils;
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryUtils.FactoryConfigurationStorage;
import ru.entaxy.platform.base.objects.factory.impl.DefaultFactory;
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<List<TrackedFactory>>, FactoryConfigurationStorage {
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(List<TrackedFactory> managedObject) {
if (managedObject == null) {
log.debug("managedObject is null");
return;
}
// List<TrackedManagedFactory> processedFactories = new ArrayList<>();
FactoryProcessor factoryProcessor = new FactoryProcessor();
for (TrackedFactory tf: managedObject) {
log.info("Added factory: " + tf.getId());
TrackedManagedFactory tmf = new TrackedManagedFactory(tf);
// if we already have factory with the same id
if (managedFactories.containsKey(tmf.factoryId)) {
tmf = managedFactories.get(tmf.factoryId);
// remove old service
tmf.deactivate();
tmf.reload(tf);
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);
}
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()) {
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);
}*/
}
@Override
public void modified(List<TrackedFactory> managedObject) {
// TODO Auto-generated method stub
}
@Override
public void removed(List<TrackedFactory> managedObject) {
if (managedObject == null)
return;
for (TrackedFactory tf: managedObject) {
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 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")) {
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
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) {
reload(factory);
}
public void reload(TrackedFactory factory) {
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());
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;
}
}
}

View File

@ -0,0 +1,62 @@
{
"factory": {
"id": "base-object",
"type": "entaxy.runtime.object",
"description": "Abstract object",
"isAbstract": true,
"label": "object"
},
"entaxy.runtime.object": {
"isEntaxyObject": true
},
"fields": {
"objectId": {
"displayName": "Object Id",
"type": "String",
"required": true,
"immutable": true,
"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
}
}
}
}
},
"outputs": {
"init": {
"isDefault": true,
"fields": {
"##publish": {}
}
}
}
}

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://www.apache.org/licenses/LICENSE-2.0
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.

View File

@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.entaxy.esb.platform.runtime</groupId>
<artifactId>base</artifactId>
<version>1.8.3</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>resources</artifactId>
<packaging>pom</packaging>
<name>ENTAXY :: PLATFORM :: BASE :: RESOURCES</name>
<description>ENTAXY :: PLATFORM :: BASE :: RESOURCES</description>
<modules>
<module>resources-api</module>
<module>resources-service</module>
<module>resources-management</module>
</modules>
</project>

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://www.apache.org/licenses/LICENSE-2.0
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.

View File

@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>resources</artifactId>
<version>1.8.3</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.base.resources</groupId>
<artifactId>resources-api</artifactId>
<packaging>bundle</packaging>
<name>ENTAXY :: PLATFORM :: BASE :: RESOURCES :: API</name>
<description>ENTAXY :: PLATFORM :: BASE :: RESOURCES :: API</description>
<properties>
<bundle.osgi.export.pkg>ru.entaxy.esb.resources</bundle.osgi.export.pkg>
</properties>
</project>

View File

@ -0,0 +1,36 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-api
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources;
import java.io.InputStream;
import java.net.URL;
public interface EntaxyResource {
InputStream getInputStream();
String getAsString();
void save(InputStream inputStream);
boolean exists();
URL getLocation();
}

View File

@ -0,0 +1,27 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-api
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources;
public interface EntaxyResourceProvider {
String getProtocol();
EntaxyResource getResource(String location);
}

View File

@ -0,0 +1,26 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-api
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources;
public interface EntaxyResourceService {
EntaxyResource getResource(String location);
}

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://www.apache.org/licenses/LICENSE-2.0
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.

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>resources</artifactId>
<version>1.8.3</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.base.resources</groupId>
<artifactId>resources-management</artifactId>
<packaging>bundle</packaging>
<name>ENTAXY :: PLATFORM :: BASE :: RESOURCES :: MANAGEMENT</name>
<description>ENTAXY :: PLATFORM :: BASE :: RESOURCES :: MANAGEMENT</description>
<properties>
<bundle.osgi.export.pkg>ru.entaxy.esb.resources.management</bundle.osgi.export.pkg>
<bundle.osgi.private.pkg>ru.entaxy.esb.resources.management.impl</bundle.osgi.private.pkg>
</properties>
<dependencies>
<dependency>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>management-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ru.entaxy.esb.platform.runtime.base.resources</groupId>
<artifactId>resources-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,38 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-management
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources.management;
import ru.entaxy.esb.platform.base.management.core.api.MBeanAnnotated;
import ru.entaxy.esb.platform.base.management.core.api.MBeanExportPolicy;
import ru.entaxy.esb.platform.base.management.core.api.Operation;
import ru.entaxy.esb.platform.base.management.core.api.Parameter;
@MBeanAnnotated(policy = MBeanExportPolicy.ANNOTATED_ONLY)
public interface EntaxyResourceServiceMBean {
public static final String RESOURCE_SERVICE_KEY = "category";
public static final String RESOURCE_SERVICE_KEY_VALUE = "resource";
@Operation(desc = "Get resource from location")
String getResource(
@Parameter(name = "location", desc = "Location of the resource") String location) throws Exception;
}

View File

@ -0,0 +1,58 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-management
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources.management.impl;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.platform.base.management.core.ManagementCore;
import ru.entaxy.esb.platform.base.management.core.api.AnnotatedMBean;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.esb.resources.management.EntaxyResourceServiceMBean;
import javax.management.DynamicMBean;
import javax.management.MBeanRegistration;
import javax.management.NotCompliantMBeanException;
@Component(service = { EntaxyResourceServiceMBean.class, DynamicMBean.class, MBeanRegistration.class }, property = {
ManagementCore.JMX_OBJECTNAME + "=" + ManagementCore.Q_RUNTIME_S + "," + EntaxyResourceServiceMBean.RESOURCE_SERVICE_KEY + "="
+ EntaxyResourceServiceMBean.RESOURCE_SERVICE_KEY_VALUE }, scope = ServiceScope.SINGLETON, immediate = true)
public class EntaxyResourceServiceMBeanImpl extends AnnotatedMBean<EntaxyResourceServiceMBean>
implements EntaxyResourceServiceMBean {
private static final Logger log = LoggerFactory.getLogger(EntaxyResourceServiceMBeanImpl.class);
protected BundleContext bundleContext;
@Reference(cardinality = ReferenceCardinality.MANDATORY
, service = EntaxyResourceService.class
, collectionType = CollectionType.SERVICE)
EntaxyResourceService entaxyResourceService;
public EntaxyResourceServiceMBeanImpl() throws NotCompliantMBeanException {
super(EntaxyResourceServiceMBean.class);
}
@Override
public String getResource(String location) throws Exception {
return entaxyResourceService.getResource(location).getAsString();
}
}

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://www.apache.org/licenses/LICENSE-2.0
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.

View File

@ -0,0 +1,49 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>resources</artifactId>
<version>1.8.3</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.base.resources</groupId>
<artifactId>resources-service</artifactId>
<packaging>bundle</packaging>
<name>ENTAXY :: PLATFORM :: BASE :: RESOURCES :: SERVICE</name>
<description>ENTAXY :: PLATFORM :: BASE :: RESOURCES :: SERVICE</description>
<properties>
<bundle.osgi.export.pkg>ru.entaxy.esb.resources.provider</bundle.osgi.export.pkg>
<bundle.osgi.private.pkg>
ru.entaxy.esb.resources.impl,
ru.entaxy.esb.resources.tracker
</bundle.osgi.private.pkg>
</properties>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>base-support</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ru.entaxy.esb.platform.runtime.base.resources</groupId>
<artifactId>resources-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,80 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-service
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources.impl;
import java.util.HashMap;
import java.util.Map;
import org.osgi.service.component.annotations.CollectionType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.resources.EntaxyResource;
import ru.entaxy.esb.resources.EntaxyResourceProvider;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.platform.base.support.CommonUtils;
@Component (service = EntaxyResourceService.class, immediate = true)
public class EntaxyResourceServiceImpl implements EntaxyResourceService {
private static final Logger log = LoggerFactory.getLogger(EntaxyResourceServiceImpl.class);
protected Map<String, EntaxyResourceProvider> providers = new HashMap<>();
@Reference (cardinality = ReferenceCardinality.MULTIPLE, collectionType = CollectionType.SERVICE
, policyOption = ReferencePolicyOption.GREEDY
, unbind = "removeProvider")
public void addProvider(EntaxyResourceProvider provider) {
synchronized (providers) {
this.providers.put(provider.getProtocol(), provider);
log.info("RESOURCE PROVIDER ADDED: " + provider.getProtocol());
}
}
public void removeProvider(EntaxyResourceProvider provider) {
synchronized (providers) {
this.providers.remove(provider.getProtocol());
}
}
@Override
public EntaxyResource getResource(String location) {
if (!CommonUtils.isValid(location))
return null;
int index = location.indexOf(":");
if (index>0) {
String protocol = location.substring(0, index);
String path = location.substring(index+1);
if (providers.containsKey(protocol)) {
return providers.get(protocol).getResource(path);
} else {
log.warn("Provider not found for protocol: [{}]", protocol);
return null;
}
}
return null;
}
}

View File

@ -0,0 +1,152 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-service
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources.provider;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.resources.EntaxyResource;
import ru.entaxy.esb.resources.EntaxyResourceProvider;
public class FileResourceProvider implements EntaxyResourceProvider {
private static final Logger log = LoggerFactory.getLogger(FileResourceProvider.class);
private String protocol;
private String rootDirectory;
private File root;
@Override
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public String getRootDirectory() {
return rootDirectory;
}
public void setRootDirectory(String rootDirectory) {
this.rootDirectory = rootDirectory;
root = new File(this.rootDirectory);
if (!root.exists())
root.mkdirs();
}
@Override
public EntaxyResource getResource(String location) {
Path rootPath = root.toPath();
Path targetPath = Paths.get(rootPath.toString(), location);
log.debug("TARGET PATH :: " + targetPath.toAbsolutePath().toString());
File targetFile = new File(targetPath.toAbsolutePath().toString());
log.debug("TARGET FILE :: " + targetFile.getAbsolutePath());
return new FileResource(targetFile);
}
public static class FileResource implements EntaxyResource {
private File file;
public FileResource(File file) {
this.file = file;
}
@Override
public InputStream getInputStream() {
if (!exists())
return null;
try {
return file.toURI().toURL().openStream();
} catch (IOException e) {
FileResourceProvider.log.error("Error getting resource", e);
return null;
}
}
@Override
public String getAsString() {
if (!exists())
return null;
try {
return IOUtils.toString(getInputStream());
} catch (IOException e) {
FileResourceProvider.log.error("Error getting resource as string", e);
}
return null;
}
@Override
public void save(InputStream inputStream) {
if (!file.exists())
try {
log.debug("\nMAKE DIRS", file.getParentFile().getAbsolutePath());
file.getParentFile().mkdirs();
// file.createNewFile();
} catch (Exception e1) {
log.error("Error creating resource", e1);
}
try (FileOutputStream fileOutputStream = new FileOutputStream(file)){
FileChannel channel = fileOutputStream.getChannel();
FileLock lock = channel.lock();
byte[] bytes = IOUtils.toByteArray(inputStream);
channel.write(ByteBuffer.wrap(bytes));
lock.release();
channel.close();
IOUtils.closeQuietly(fileOutputStream);
} catch (Exception e) {
log.error("Error saving resource", e);
}
}
@Override
public boolean exists() {
return file.exists();
}
@Override
public URL getLocation() {
try {
return this.file.toURI().toURL();
} catch (MalformedURLException e) {
return null;
}
}
}
}

View File

@ -0,0 +1,103 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-service
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources.tracker;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
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.CommonUtils;
public class ResourceProvider {
private static final Logger log = LoggerFactory.getLogger(ResourceProvider.class);
public static final String RESOURCE_PATH = "/ru/entaxy/resource";
protected Bundle bundle;
protected Map<String, List<ResourceDescriptor>> resources = new HashMap<>();
public ResourceProvider(Bundle bundle) {
this.bundle = bundle;
}
public Map<String, List<ResourceDescriptor>> getResources(){
if (!resources.isEmpty())
return resources;
Enumeration<URL> foundEntries = bundle.findEntries(ResourceProvider.RESOURCE_PATH, "*.*", true);
while (foundEntries.hasMoreElements()) {
URL entry = foundEntries.nextElement();
log.debug("FOUND :: " + entry.toString());
if (entry.toString().endsWith("/")) {
log.debug(":: .. is folder");
continue;
}
String localPath = entry.toString();
localPath = localPath.substring(localPath.indexOf(ResourceProvider.RESOURCE_PATH) + ResourceProvider.RESOURCE_PATH.length() + 1);
String resourceName = localPath.substring(localPath.lastIndexOf("/")+1);
String path = localPath.lastIndexOf("/")>=0
?localPath.substring(0, localPath.lastIndexOf("/"))
:"";
int splitIndex = path.indexOf("/");
String protocol = splitIndex>0
?path.substring(0, splitIndex)
:"";
if (splitIndex>0)
path = path.substring(splitIndex+1);
if (!CommonUtils.isValid(protocol) || !CommonUtils.isValid(resourceName))
continue;
if (!resources.containsKey(protocol))
resources.put(protocol, new ArrayList<>());
resources.get(protocol).add(new ResourceDescriptor(entry, path + "/" + resourceName));
}
return resources;
}
public static class ResourceDescriptor {
public URL url;
public String location;
public ResourceDescriptor(URL url, String location) {
this.url = url;
this.location = location;
}
}
}

View File

@ -0,0 +1,39 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-service
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources.tracker;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import ru.entaxy.platform.base.support.osgi.tracker.UniformBundleTrackerCustomizer;
public class ResourceProviderCustomizer extends UniformBundleTrackerCustomizer<List<ResourceProvider>> {
@Override
protected List<ResourceProvider> createManagedObject(Bundle bundle, BundleEvent event,
Map<String, List<?>> filterResults) {
return Collections.singletonList(new ResourceProvider(bundle));
}
}

View File

@ -0,0 +1,92 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-service
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources.tracker;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.resources.EntaxyResource;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.esb.resources.tracker.ResourceProvider.ResourceDescriptor;
import ru.entaxy.platform.base.support.osgi.tracker.BundleTrackerCustomizerListener;
public class ResourceProviderCustomizerListener implements BundleTrackerCustomizerListener<List<ResourceProvider>> {
private static final Logger log = LoggerFactory.getLogger(ResourceProviderCustomizerListener.class);
protected BundleContext bundleContext;
protected EntaxyResourceService entaxyResourceService;
public ResourceProviderCustomizerListener(BundleContext context, EntaxyResourceService service) {
this.bundleContext = context;
this.entaxyResourceService = service;
}
@Override
public void added(List<ResourceProvider> managedObject) {
for (ResourceProvider provider: managedObject) {
Map<String, List<ResourceDescriptor>> resources = provider.getResources();
String message = "";
message += "\nFOUND RESOURCES";
for (String protocol: resources.keySet()) {
message += "\n\tPROTOCOL :: " + protocol;
List<ResourceDescriptor> list = resources.get(protocol);
for (ResourceDescriptor rd: list) {
message += "\n\t\t :: " + rd.location + " | " + rd.url.toString();
EntaxyResource resource = entaxyResourceService.getResource(protocol + ":" + rd.location);
if (resource == null) {
message += "\n\t\t -> NULL";
} else {
try {
resource.save(rd.url.openStream());
message += "\n\t\t -> " + resource.getAsString();
} catch (IOException e) {
log.error("Error saving resource", e);
}
}
}
}
log.debug(message);
}
}
@Override
public void modified(List<ResourceProvider> managedObject) {
// TODO Auto-generated method stub
}
@Override
public void removed(List<ResourceProvider> managedObject) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,62 @@
/*-
* ~~~~~~licensing~~~~~~
* resources-service
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.resources.tracker;
import java.util.List;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.util.tracker.BundleTracker;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.platform.base.support.osgi.tracker.BundleTrackerUtils;
import ru.entaxy.platform.base.support.osgi.tracker.filter.BundleHeaderFilter;
@Component
public class TrackerManager {
protected BundleContext bundleContext;
protected BundleTracker<List<ResourceProvider>> providerTracker;
@Reference (cardinality = ReferenceCardinality.MANDATORY)
EntaxyResourceService entaxyResourceService;
@Activate
public void activate(ComponentContext componentContext) {
this.bundleContext = componentContext.getBundleContext();
providerTracker = BundleTrackerUtils.<List<ResourceProvider>>createBuilder()
.addFilter(
(new BundleHeaderFilter()).header("Entaxy-Resource-Provider")
)
.customizer(
(new ResourceProviderCustomizer())
.listener(new ResourceProviderCustomizerListener(bundleContext, entaxyResourceService))
)
.bundleState(Bundle.ACTIVE | Bundle.INSTALLED | Bundle.RESOLVED)
.get();
providerTracker.open(); }
}

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~~~~~~licensing~~~~~~
base
==========
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
http://www.apache.org/licenses/LICENSE-2.0
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.
~~~~~~/licensing~~~~~~
-->
<features name="entaxy-platform-base-support-${project.version}"
xmlns="http://karaf.apache.org/xmlns/features/v1.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.3.0 http://karaf.apache.org/xmlns/features/v1.3.0">
<repository>mvn:org.apache.camel.karaf/apache-camel/${camel.version}/xml/features</repository>
<repository>mvn:ru.entaxy.esb.underlying/entaxy-underlying-features/${project.version}/xml/features</repository>
<!-- legacy repo -->
<repository>mvn:ru.entaxy.esb.system/system-parent/${project.version}/xml/basics</repository>
<feature name="base-support" version="${project.version}" start-level="70">
<bundle>mvn:ru.entaxy.esb.platform.runtime.base/base-support/${project.version}</bundle>
</feature>
<feature name="resources" version="${project.version}" start-level="70">
<feature version="${project.version}" dependency="true">base-support</feature>
<bundle>mvn:ru.entaxy.esb.platform.runtime.base.resources/resources-api/${project.version}</bundle>
<bundle>mvn:ru.entaxy.esb.platform.runtime.base.resources/resources-service/${project.version}</bundle>
<bundle>mvn:ru.entaxy.esb.platform.runtime.base.resources/resources-management/${project.version}</bundle>
</feature>
<feature name="generator" version="${project.version}" start-level="70">
<feature version="${project.version}" dependency="true">base-support</feature>
<bundle>mvn:ru.entaxy.esb.platform.runtime.base.connecting.generator/generator-api/${project.version}</bundle>
<bundle>mvn:ru.entaxy.esb.platform.runtime.base.connecting.generator/generator-factory/${project.version}</bundle>
<bundle>mvn:ru.entaxy.esb.platform.runtime.base.connecting.generator/template-service-shell/${project.version}</bundle>
<bundle>mvn:ru.entaxy.esb.platform.runtime.base.connecting.generator/ftl-generator/${project.version}</bundle>
<bundle>mvn:ru.entaxy.esb.platform.runtime.base.connecting.generator/common-templates-collection/${project.version}</bundle>
</feature>
</features>

View File

@ -0,0 +1,128 @@
/*-
* ~~~~~~licensing~~~~~~
* schema-impl
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.runtime.core.infrastructure.schema.resolver.resource;
import java.io.File;
import java.nio.file.Files;
import java.util.Calendar;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.file.GenericFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.ResourceService;
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.entity.Resource;
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.entity.ResourceInfo;
public class ResourceLoader implements Processor {
private static final Logger log = LoggerFactory.getLogger(ResourceLoader.class);
protected ResourceService resourceService;
public ResourceService getResourceService() {
return resourceService;
}
public void setResourceService(ResourceService resourceService) {
this.resourceService = resourceService;
}
@Override
public void process(Exchange exchange) throws Exception {
log.info("BODY IS [{}]\nHEADERS ARE:\n{}"
, exchange.getIn().getBody().getClass().getName()
, exchange.getIn().getHeaders().toString());
String camelFileName = exchange.getIn().getHeader("CamelFilePath", String.class);
String fileNameAndPath = camelFileName;//.substring(0, camelFileName.lastIndexOf("."));
String fileName = getFileName(camelFileName);
String filePath = getFilePath(camelFileName);
String fileType = camelFileName.substring(camelFileName.lastIndexOf(".")+1);
Resource resource = null;
try {
resource = resourceService.getResourceByFullName(fileNameAndPath).orElse(null);
} catch (Exception e) {
}
if (resource ==null) {
resource = new Resource();
resource.setCreatedBy("admin");
resource.setCreatedDate(Calendar.getInstance().getTime());
GenericFile<?> genericFile = exchange.getIn().getBody(GenericFile.class);
log.info("FILE IS {}", genericFile.getFile().getClass().getName());
resource.setResourceValue(
Files.readAllBytes(((File)genericFile.getFile()).toPath())
);
long resourceId = resourceService.loadResource(resource);
ResourceInfo resourceInfo = new ResourceInfo();
resourceInfo.setCreatedBy("admin");
resourceInfo.setCreatedDate(Calendar.getInstance().getTime());
resourceInfo.setConvertor(false);
resourceInfo.setDescription("Automatically loaded with type [" + fileType + "]");
resourceInfo.setName(fileName);
resourceInfo.setPath(filePath);
resourceInfo.setVersion("1.0");
resourceInfo.setResourceId(resourceId);
long resourceInfoId = resourceService.loadResourceInfo(resourceInfo);
log.info("ResourceInfo id is [" + resourceInfoId + "]");
} else {
GenericFile<?> genericFile = exchange.getIn().getBody(GenericFile.class);
log.info("FILE IS {}", genericFile.getFile().getClass().getName());
resource.setResourceValue(
Files.readAllBytes(((File)genericFile.getFile()).toPath())
);
resourceService.reloadResource(resource);
}
}
private String getFileName(String fileNameAndPath) {
String[] splitted = fileNameAndPath.split(File.separator);
return splitted[splitted.length-1];
}
private String getFilePath(String fileNameAndPath) {
String[] splitted = fileNameAndPath.split(File.separator);
String path = null;
if (splitted.length>1) {
path = fileNameAndPath.substring(0, fileNameAndPath.length() - splitted[splitted.length-1].length());
}
return path;
}
}

View File

@ -0,0 +1,93 @@
/*-
* ~~~~~~licensing~~~~~~
* schema-impl
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.runtime.core.infrastructure.schema.resolver.resource;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.osgi.service.component.annotations.CollectionType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.url.AbstractURLStreamHandlerService;
import org.osgi.service.url.URLStreamHandlerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.ResourceService;
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.entity.Resource;
@Component(service = URLStreamHandlerService.class, property = "url.handler.protocol=resource-registry", immediate = true)
public class ResourceRegistryURLResolver extends AbstractURLStreamHandlerService {
private static final Logger log = LoggerFactory.getLogger(ResourceRegistryURLResolver.class);
@Reference (collectionType = CollectionType.SERVICE, cardinality = ReferenceCardinality.MANDATORY)
ResourceService resourceService;
protected static class SchemaRegistryURLConnection extends URLConnection {
ResourceService resourceService;
protected String resourceName = null;
protected String resourceVersion = null;
protected SchemaRegistryURLConnection(URL url, ResourceService resourceService) {
super(url);
this.resourceService = resourceService;
log.info("NEW CONNECTION TO: " + url.toString());
String remaining = url.toString().substring(url.toString().indexOf(":")+1);
String[] splitted = remaining.split(File.separator);
if (splitted.length>1) {
resourceVersion = splitted[splitted.length - 1];
resourceName = remaining.substring(0, remaining.length() - resourceVersion.length());
} else {
resourceName = remaining;
}
}
@Override
public void connect() throws IOException {
log.info("CONNECTING: " + url.toString());
}
@Override
public InputStream getInputStream() throws IOException {
Resource resource = resourceService.getResourceByFullName(resourceName).orElse(null);
log.info("RESOURCE [{}] {} FOUND "
, resourceName
, resource==null?"NOT":"");
if (resource == null)
return super.getInputStream();
return new ByteArrayInputStream(resource.getResourceValue());
}
}
@Override
public URLConnection openConnection(URL u) throws IOException {
return new SchemaRegistryURLConnection(u, resourceService);
}
}

View File

@ -0,0 +1,25 @@
/*-
* ~~~~~~licensing~~~~~~
* schema-impl
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.runtime.core.infrastructure.schema.resolver.resource;
public class SchemaRegistryHelper {
}

View File

@ -0,0 +1,83 @@
/*-
* ~~~~~~licensing~~~~~~
* schema-soap
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.runtime.core.infrastructure.schema.soap.cxf;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="fullName" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"fullName"
})
@XmlRootElement(name = "getResourceInfoListByFullNameRequest")
public class GetResourceInfoListByFullNameRequest {
@XmlElement(required = true)
protected String fullName;
/**
* Gets the value of the fullName property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getFullName() {
return fullName;
}
/**
* Sets the value of the fullName property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setFullName(String value) {
this.fullName = value;
}
}

View File

@ -0,0 +1,83 @@
/*-
* ~~~~~~licensing~~~~~~
* schema-soap
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.runtime.core.infrastructure.schema.soap.cxf;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="path" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"path"
})
@XmlRootElement(name = "getResourceInfoListByFullPathRequest")
public class GetResourceInfoListByFullPathRequest {
@XmlElement(required = true)
protected String path;
/**
* Gets the value of the path property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPath() {
return path;
}
/**
* Sets the value of the path property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPath(String value) {
this.path = value;
}
}

View File

@ -0,0 +1,83 @@
/*-
* ~~~~~~licensing~~~~~~
* schema-soap
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.runtime.core.infrastructure.schema.soap.cxf;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="path" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"path"
})
@XmlRootElement(name = "getResourceInfoListByPathRequest")
public class GetResourceInfoListByPathRequest {
@XmlElement(required = true)
protected String path;
/**
* Gets the value of the path property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPath() {
return path;
}
/**
* Sets the value of the path property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPath(String value) {
this.path = value;
}
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~~~~~~licensing~~~~~~
storage-esb_entaxy
==========
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
http://www.apache.org/licenses/LICENSE-2.0
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.
~~~~~~/licensing~~~~~~
-->
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="011001" author="v.s.borodina" context="main">
<insert tableName="permission">
<column name="object_id" value="1"/>
<column name="object_type" value="account"/>
<column name="subject_id" value="uniform-exchange"/>
<column name="subject_type" value="service"/>
<column name="action" value="default"/>
</insert>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,28 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-api
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.api;
public interface EntaxyFactoryDataProcessor {
default Object processDefaultValue(Object currentValue) {
return currentValue;
}
}

View File

@ -0,0 +1,20 @@
{
"general": {
"*":{"printOutput":false, "maxCount": 50},
"add-config":{},
"process-resources":{},
"validate":{},
"generate":{},
"build":{"artifact.version.policy":"dated-embedded"},
"install":{"installLocal":false, "update":""},
"deploy":{"deployLocal":false},
"store": {}
},
"local": {
"install":{"installLocal":true},
"deploy":{"deployLocal":true}
},
"debug": {
"*":{"printOutput":true}
}
}

View File

@ -0,0 +1,26 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.builder;
public interface BuiltObject {
Object getObject();
}

View File

@ -0,0 +1,32 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.builder;
import java.util.Collections;
import org.apache.commons.collections4.list.AbstractLinkedList;
public class BuiltObjectList extends AbstractLinkedList<BuiltObject> {
public BuiltObjectList() {
super(Collections.emptyList());
}
}

View File

@ -0,0 +1,35 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.builder;
public class DefaultBuiltObject implements BuiltObject {
protected Object object;
public DefaultBuiltObject(Object object) {
this.object = object;
}
@Override
public Object getObject() {
return object;
}
}

View File

@ -0,0 +1,31 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.builder;
import java.util.Map;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
public interface ObjectBuilder {
boolean isBuildable(Generated generated);
BuiltObject build(Generated generated, Map<String, Object> instructions) throws Exception;
}

View File

@ -0,0 +1,35 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.deployer;
public class DefaultDeployedObject implements DeployedObject {
protected Object object;
public DefaultDeployedObject(Object object) {
this.object = object;
}
@Override
public Object getObject() {
return object;
}
}

View File

@ -0,0 +1,26 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.deployer;
public interface DeployedObject {
Object getObject();
}

View File

@ -0,0 +1,32 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.deployer;
import java.util.Collections;
import org.apache.commons.collections4.list.AbstractLinkedList;
public class DeployedObjectList extends AbstractLinkedList<DeployedObject> {
public DeployedObjectList() {
super(Collections.emptyList());
}
}

View File

@ -0,0 +1,31 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.deployer;
import java.util.Map;
import ru.entaxy.platform.core.producer.executor.builder.BuiltObject;
public interface ObjectDeployer {
boolean isDeployable(BuiltObject object);
DeployedObject deploy(BuiltObject object, Map<String, Object> instructions) throws Exception;
}

View File

@ -0,0 +1,35 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.installer;
public class DefaultInstalledObject implements InstalledObject {
protected Object object;
public DefaultInstalledObject(Object object) {
this.object = object;
}
@Override
public Object getObject() {
return object;
}
}

View File

@ -0,0 +1,26 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.installer;
public interface InstalledObject {
Object getObject();
}

View File

@ -0,0 +1,32 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.installer;
import java.util.Collections;
import org.apache.commons.collections4.list.AbstractLinkedList;
public class InstalledObjectList extends AbstractLinkedList<InstalledObject> {
public InstalledObjectList() {
super(Collections.emptyList());
}
}

View File

@ -0,0 +1,31 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.installer;
import java.util.Map;
import ru.entaxy.platform.core.producer.executor.deployer.DeployedObject;
public interface ObjectInstaller {
boolean isInstallable(DeployedObject object);
InstalledObject install(DeployedObject object, Map<String, Object> instructions) throws Exception;
}

View File

@ -0,0 +1,53 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.support;
import java.util.Map;
import ru.entaxy.platform.core.producer.api.EntaxyProducerService.INSTRUCTIONS;
public class AbstractPrintOutputSupport implements PrintOutputSupport{
protected boolean isPrintOutput = false;
@Override
public boolean isPrintOutput() {
return isPrintOutput;
}
@Override
public void setPrintOutput(boolean isPrintOutput) {
this.isPrintOutput = isPrintOutput;
}
protected void setPrintOutput(Map<String, Object> parameters) {
if (parameters == null)
return;
if (parameters.containsKey(INSTRUCTIONS.PRINT_OUTPUT)) {
Object val = parameters.get(INSTRUCTIONS.PRINT_OUTPUT);
if (val == null)
return;
if (val instanceof Boolean)
this.isPrintOutput = (Boolean)val;
}
}
}

View File

@ -0,0 +1,307 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.support;
import java.util.Map;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
import ru.entaxy.platform.base.objects.EntaxyObject.FIELDS;
import ru.entaxy.platform.base.objects.EntaxyObject.HEADERS;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.core.artifact.Artifact;
import ru.entaxy.platform.core.artifact.ArtifactManifest;
import ru.entaxy.platform.core.artifact.Artifacts;
import ru.entaxy.platform.core.artifact.Blueprint;
import ru.entaxy.platform.core.artifact.DeployedArtifact;
import ru.entaxy.platform.core.artifact.Manifested;
import ru.entaxy.platform.core.artifact.capabilities.ManifestCapabilityHelper;
import ru.entaxy.platform.core.artifact.installer.builder.ClusterInstaller;
import ru.entaxy.platform.core.artifact.installer.builder.InstallationResult;
import ru.entaxy.platform.core.artifact.installer.builder.Installer;
import ru.entaxy.platform.core.artifact.installer.builder.LocalInstaller;
import ru.entaxy.platform.core.artifact.installer.builder.typed.BlueprintInstaller;
import ru.entaxy.platform.core.artifact.service.ArtifactService;
import ru.entaxy.platform.core.producer.api.EntaxyProducerService;
import ru.entaxy.platform.core.producer.executor.CommandInstructions;
import ru.entaxy.platform.core.producer.executor.builder.BuiltObject;
import ru.entaxy.platform.core.producer.executor.builder.DefaultBuiltObject;
import ru.entaxy.platform.core.producer.executor.builder.ObjectBuilder;
import ru.entaxy.platform.core.producer.executor.commands.Deploy;
import ru.entaxy.platform.core.producer.executor.commands.Install;
import ru.entaxy.platform.core.producer.executor.deployer.DefaultDeployedObject;
import ru.entaxy.platform.core.producer.executor.deployer.DeployedObject;
import ru.entaxy.platform.core.producer.executor.deployer.ObjectDeployer;
import ru.entaxy.platform.core.producer.executor.generationmodel.GeneratedHeaders;
import ru.entaxy.platform.core.producer.executor.installer.DefaultInstalledObject;
import ru.entaxy.platform.core.producer.executor.installer.InstalledObject;
import ru.entaxy.platform.core.producer.executor.installer.ObjectInstaller;
@Component (service = { ObjectBuilder.class, ObjectDeployer.class, ObjectInstaller.class}, immediate = true)
public class ArtifactSupport implements ObjectBuilder, ObjectDeployer, ObjectInstaller {
private static final Logger log = LoggerFactory.getLogger(ArtifactSupport.class);
@Reference (cardinality = ReferenceCardinality.MANDATORY)
ArtifactService artifactService;
/*
* ObjectBuilder
*/
@Override
public boolean isBuildable(Generated generated) {
Artifact artifact = Artifacts.fromGenerated(generated);
if ((artifact == null) || Artifact.ARTIFACT_CATEGORY_UNKNOWN.equals(artifact.getCategory())
|| !CommonUtils.isValid(artifact.getCategory())) {
return false;
}
return true;
}
@Override
public BuiltObject build(Generated generated, Map<String, Object> instructions) throws Exception {
LocalPrintOutput printer = new LocalPrintOutput(instructions);
Artifact artifact = Artifacts.fromGenerated(generated);
if ((artifact == null) || Artifact.ARTIFACT_CATEGORY_UNKNOWN.equals(artifact.getCategory())
|| !CommonUtils.isValid(artifact.getCategory())) {
log.info("Artifact is not buildable");
return null;
}
log.info("Built artifact of category [{}]", artifact.getCategory());
Map<String, String> headers = GeneratedHeaders.getHeaders(
//generated.getProperties()
EntaxyObjectPropertiesHelper.getMainObjectProperties(generated.getProperties())
).getAsStringMap();
String mainObjectValue = headers.get(HEADERS.MAIN_OBJECT);
if (!CommonUtils.isValid(mainObjectValue))
throw new Exception("Main object not found");
String[] mainObjectData = mainObjectValue.split(":");
if (mainObjectData.length<2)
throw new Exception("Main object not complete: [" + mainObjectValue + "]");
String versionPolicy = generated.getProperties().getOrDefault(
EntaxyProducerService.INSTRUCTIONS.ARTIFACT.VERSION_POLICY,
instructions.getOrDefault(
EntaxyProducerService.INSTRUCTIONS.ARTIFACT.VERSION_POLICY
, ""))
.toString();
String timestamp = generated.getProperties().getOrDefault(
EntaxyProducerService.INSTRUCTIONS.ARTIFACT.TIMESTAMP,
instructions.getOrDefault(
EntaxyProducerService.INSTRUCTIONS.ARTIFACT.TIMESTAMP
, ""))
.toString();
artifact.getCoordinates()
.groupId(mainObjectData[1])
.artifactId(mainObjectData[0])
.version("1")
.versionPolicy(versionPolicy)
.timestamp(timestamp);
if (artifact instanceof Manifested) {
ArtifactManifest manifest = ((Manifested)artifact).getManifest();
manifest.getCustomAttributes().putAll(headers);
// Generate provided capabilities for every included object
ManifestCapabilityHelper helper = new ManifestCapabilityHelper(manifest);
String objectsValue = headers.getOrDefault(HEADERS.GENERATED_OBJECTS, "");
if (CommonUtils.isValid(objectsValue)) {
String[] objects = objectsValue.split(",");
for (int i=0; i<objects.length; i++) {
String[] objectData = objects[i].split(":");
if (objectData.length<2)
continue;
String objectId = objectData[0];
String objectType = objectData[1];
if (!CommonUtils.isValid(objectId) || !CommonUtils.isValid(objectType))
continue;
objectId = objectId.trim();
objectType = objectType.trim();
Map<String, Object> attributes = null;
Map<String, Object> objectProperties = EntaxyObjectPropertiesHelper
.getPropertiesFor(objectId, objectType, generated.getProperties());
if (objectProperties.containsKey(FIELDS.FIELDS_TO_PUBLISH)) {
Object map = objectProperties.get(FIELDS.FIELDS_TO_PUBLISH);
if (map != null) {
attributes = (Map<String, Object>)((Map<String, Object>)map).get(objectId);
}
}
helper.provideCapability(objectType).attributes(attributes);
}
helper.save();
}
}
artifact.getProperties().putAll(generated.getProperties());
// TODO get value from manifest
// ArtifactManifest must be improved to provide read access to all attributes
if (!artifact.getProperties().containsKey(Constants.BUNDLE_SYMBOLICNAME)) {
artifact.getProperties().put(Constants.BUNDLE_SYMBOLICNAME
, artifact.getCoordinates().getGroupId()
+ "." + artifact.getCoordinates().getArtifactId());
}
printer.printOutput("\n\t == " + artifact.getCoordinates().toString() + " ==\n");
printer.printOutput(new String(artifact.asByteArray()));
printer.printOutput("\n\t == \n");
return new DefaultBuiltObject(artifact);
}
/*
* ObjectDeployer
*/
@Override
public boolean isDeployable(BuiltObject object) {
return object.getObject() instanceof Artifact;
}
@Override
public DeployedObject deploy(BuiltObject object, Map<String, Object> instructions) throws Exception {
if (!(object.getObject() instanceof Artifact)) {
return null;
}
LocalPrintOutput printer = new LocalPrintOutput(instructions);
boolean deployLocal = false;
Object deployLocalValue = instructions.get(Deploy.DEPLOY_LOCAL_INSTRUCTION);
if (deployLocalValue != null)
if (deployLocalValue instanceof Boolean)
deployLocal = (Boolean)deployLocalValue;
Artifact artifact = (Artifact)object.getObject();
DeployedArtifact da = deployLocal
?artifactService.deployLocal(artifact)
:artifactService.deployShared(artifact);
printer.printOutput("DEPLOYED: ["
+ da.getLocation()
+ "]");
return new DefaultDeployedObject(da);
}
/*
* ObjectInstaller
*/
@Override
public boolean isInstallable(DeployedObject object) {
return object.getObject() instanceof DeployedArtifact;
}
@Override
public InstalledObject install(DeployedObject object, Map<String, Object> instructions) throws Exception {
if (!isInstallable(object))
return null;
LocalPrintOutput printer = new LocalPrintOutput(instructions);
CommandInstructions commandInstructions = new CommandInstructions(instructions);
boolean installLocal =
commandInstructions.has(Install.INSTALL_LOCAL_INSTRUCTION)
?commandInstructions.getBoolean(Install.INSTALL_LOCAL_INSTRUCTION)
:false;
boolean installOnlyIfMissing =
commandInstructions.has(Install.INSTALL_ONLY_IF_MISSING_INSTRUCTION)
?commandInstructions.getBoolean(Install.INSTALL_ONLY_IF_MISSING_INSTRUCTION)
:false;
String update =
commandInstructions.has(Install.UPDATE_INSTRUCTION)
?commandInstructions.getString(Install.UPDATE_INSTRUCTION)
:null;
DeployedArtifact da = (DeployedArtifact)object.getObject();
InstallationResult result = null;
Installer<?> installer = null;
String artifactUpdate = update;
printer.printOutput("-> Installing artifact: [" + da.getArtifact().getCoordinates().toString() + "]");
if (installLocal) {
LocalInstaller localInstaller = artifactService.installers().local()
.artifact(da);
installer = localInstaller;
printer.printOutput("-> Installing locally");
} else {
ClusterInstaller clusterInstaller = artifactService.installers().cluster()
.artifact(da);
installer = clusterInstaller;
printer.printOutput("-> Installing clustered");
}
// TODO add support for other types when they appear
if (da.getArtifact().getCategory().equals(Blueprint.ARTIFACT_CATEGORY_BLUEPRINT)) {
// we're installing blueprint
printer.printOutput("-> Installing: " + da.getArtifact().getCategory());
BlueprintInstaller blueprintInstaller = installer.typed(BlueprintInstaller.class);
if (installOnlyIfMissing)
blueprintInstaller.installOnlyIfMissing();
if (artifactUpdate != null) {
if (!CommonUtils.isValid(artifactUpdate)) {
artifactUpdate = da
.getArtifact().getProperties()
.getOrDefault(Constants.BUNDLE_SYMBOLICNAME, "")
.toString();
}
blueprintInstaller.update(artifactUpdate);
}
result = blueprintInstaller.start().install();
} else {
printer.printOutput("-> Unknown category: " + da.getArtifact().getCategory());
}
if (result != null) {
for (String key: da.getArtifact().getProperties().keySet())
result.getProperties().putIfAbsent(key, da.getArtifact().getProperties().get(key));
// TODO imrove Coordinates: add "asMap" method
result.getProperties().put("artifact.artifactId", da.getArtifact().getCoordinates().getArtifactId());
result.getProperties().put("artifact.groupId", da.getArtifact().getCoordinates().getGroupId());
result.getProperties().put("artifact.version", da.getArtifact().getCoordinates().getVersion());
result.getProperties().put("artifact.type", da.getArtifact().getCoordinates().getType());
result.getProperties().put("artifact.classifier", da.getArtifact().getCoordinates().getClassifier());
}
return new DefaultInstalledObject(result);
}
}

View File

@ -0,0 +1,87 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.support;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import ru.entaxy.platform.base.objects.EntaxyObject.FIELDS;
import ru.entaxy.platform.base.support.CommonUtils;
public class EntaxyObjectPropertiesHelper {
public static final String PROP_IS_MERGED = "###MERGED";
public static final String PROP_MAIN_OBJECT_DATA = "###MAIN";
public static boolean isMerged(Map<String, Object> properties) {
return (properties!=null) && (properties.containsKey(PROP_IS_MERGED));
}
public static Map<String, Object> merge(Map<String, Object> source, Map<String, Object> target){
Map<String, Object> result = new HashMap<>();
result.put(PROP_IS_MERGED, true);
result.putAll(extractObjects(target));
result.putAll(extractObjects(source));
result.put(PROP_MAIN_OBJECT_DATA, getMainObjectProperties(target));
return result;
}
public static Map<String, Object> getPropertiesFor(String objectId, String objectType, Map<String, Object> data){
Map<String, Map<String, Object>> extracted = extractObjects(data);
return extracted.getOrDefault(createKey(objectId, objectType), new HashMap<>());
}
public static Map<String, Object> getMainObjectProperties(Map<String, Object> data){
Map<String, Map<String, Object>> extracted = extractObjects(data);
if (extracted.containsKey(PROP_MAIN_OBJECT_DATA))
return (Map<String, Object>)extracted.get(PROP_MAIN_OBJECT_DATA);
if (extracted.size() >= 1)
return (Map<String, Object>)extracted.values().iterator().next();
return new HashMap<>();
}
private static String createKey(String objectId, String objectType) {
return CommonUtils.getValid(objectId, "") + ":" + CommonUtils.getValid(objectType, "");
}
private static Map<String, Map<String, Object>> extractObjects(Map<String, Object> source){
Map<String, Map<String, Object>> result = new HashMap<>();
if (isMerged(source)) {
for (Entry<String, Object> entry: source.entrySet()) {
if (PROP_IS_MERGED.equals(entry.getKey()))
continue;
if (entry.getValue() instanceof Map) {
result.put(entry.getKey(), (Map<String, Object>)entry.getValue());
}
}
} else {
String objectId = source.getOrDefault(FIELDS.OBJECT_ID, "").toString();
String objectType = source.getOrDefault(FIELDS.OBJECT_TYPE, "").toString();
if (CommonUtils.isValid(objectId) && CommonUtils.isValid(objectType)) {
String key = createKey(objectId, objectType);
result.put(key, source);
}
}
return result;
}
}

View File

@ -0,0 +1,30 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.support;
import java.util.Map;
public class LocalPrintOutput extends AbstractPrintOutputSupport {
public LocalPrintOutput(Map<String, Object> instructions) {
setPrintOutput(instructions);
}
}

View File

@ -0,0 +1,88 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.support;
import java.util.List;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
import ru.entaxy.platform.core.producer.executor.builder.BuiltObject;
import ru.entaxy.platform.core.producer.executor.builder.ObjectBuilder;
import ru.entaxy.platform.core.producer.executor.deployer.DeployedObject;
import ru.entaxy.platform.core.producer.executor.deployer.ObjectDeployer;
import ru.entaxy.platform.core.producer.executor.installer.ObjectInstaller;
@Component (service = ObjectSupportRegistry.class, immediate = true)
public class ObjectSupportRegistry {
private static ObjectSupportRegistry INSTANCE = null;
public static ObjectSupportRegistry getInstance() {
return INSTANCE;
}
@Reference (cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
volatile List<ObjectBuilder> objectBuilders;
@Reference (cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
volatile List<ObjectDeployer> objectDeployers;
@Reference (cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
volatile List<ObjectInstaller> objectInstallers;
@Activate
public void activate() {
INSTANCE = this;
}
public ObjectBuilder findBuilder(Generated generated) {
synchronized (this.objectBuilders) {
for (ObjectBuilder ob: this.objectBuilders)
if (ob.isBuildable(generated))
return ob;
}
return null;
}
public ObjectDeployer findDeployer(BuiltObject object) {
synchronized (this.objectDeployers) {
for (ObjectDeployer od: this.objectDeployers)
if (od.isDeployable(object))
return od;
}
return null;
}
public ObjectInstaller findInstaller(DeployedObject object) {
synchronized (this.objectInstallers) {
for (ObjectInstaller oi: this.objectInstallers)
if (oi.isInstallable(object))
return oi;
}
return null;
}
}

View File

@ -0,0 +1,34 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.executor.support;
public interface PrintOutputSupport {
void setPrintOutput(boolean printOutput);
boolean isPrintOutput();
default void printOutput(String message) {
if (isPrintOutput())
// OUTPUT TO CONSOLE
System.out.println(message);
};
}

View File

@ -0,0 +1,62 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.impl;
import java.util.List;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.CollectionType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.FieldOption;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import ru.entaxy.platform.core.producer.api.EntaxyFactoryDataProcessor;
@Component (service = EntaxyFactoryDataProcessorService.class, immediate = true)
public class EntaxyFactoryDataProcessorService implements EntaxyFactoryDataProcessor {
private static EntaxyFactoryDataProcessorService _INSTANCE = null;
public static EntaxyFactoryDataProcessorService getInstance() {
return _INSTANCE;
}
@Reference (cardinality = ReferenceCardinality.MULTIPLE, collectionType = CollectionType.SERVICE, fieldOption = FieldOption.UPDATE,
policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY, service = EntaxyFactoryDataProcessor.class)
List<EntaxyFactoryDataProcessor> processors;
@Activate
public void activate() {
_INSTANCE = this;
}
@Override
public Object processDefaultValue(Object currentValue) {
Object result = currentValue;
for (EntaxyFactoryDataProcessor p: processors) {
result = p.processDefaultValue(result);
}
return result;
}
}

View File

@ -0,0 +1,87 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE_MODE;
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryUtils;
import ru.entaxy.platform.base.support.JSONUtils;
import ru.entaxy.platform.core.producer.api.EntaxyProducerService;
public class InstructionsHelper {
public static final String DEFAULT_INSTRUCTIONS = "{'validate':{}}";
public static final String LIFECYCLE_DIRECTIVE = EntaxyProducerService.DIRECTIVES.LIFECYCLE;
protected JsonObject lifecyclesOrigin;
protected Map<String, JsonObject> lifecycles = new HashMap<>();
public InstructionsHelper(JsonObject lifecycles) {
super();
this.lifecyclesOrigin = lifecycles.deepCopy();
fillMap(this.lifecyclesOrigin);
}
protected void fillMap(JsonObject origin) {
for (Entry<String, JsonElement> entry: origin.entrySet())
if (entry.getValue().isJsonObject())
this.lifecycles.put(entry.getKey(), entry.getValue().getAsJsonObject().deepCopy());
}
public String prepareInstructions(String originalInstructions) {
JsonObject origin = JSONUtils.getJsonRootObject(originalInstructions);
JsonObject result = new JsonObject();
if (origin.has(LIFECYCLE_DIRECTIVE)) {
JsonElement directiveValue = origin.get(LIFECYCLE_DIRECTIVE);
List<String> lcIdToApply = new ArrayList<>();
List<JsonObject> lcToApply = new ArrayList<>();
if (directiveValue.isJsonPrimitive())
lcIdToApply.add(directiveValue.getAsString());
if (directiveValue.isJsonArray()) {
JsonArray ja = directiveValue.getAsJsonArray();
for (int i=0; i<ja.size(); i++)
lcIdToApply.add(ja.get(i).getAsString());
}
origin.remove(LIFECYCLE_DIRECTIVE);
for (String id: lcIdToApply)
if (this.lifecycles.containsKey(id))
EntaxyFactoryUtils.processObjectOverriding(
result
, this.lifecycles.get(id)
, OVERRIDE_MODE.UPDATE);
}
EntaxyFactoryUtils.processObjectOverriding(
result
, origin
, OVERRIDE_MODE.UPDATE);
return result.toString();
}
}

View File

@ -0,0 +1,45 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.support;
public abstract class AbstractConsumerAwareMetadataStorage implements MetadataStorage {
protected String prefix = "";
protected MetadataStorageConsumer consumer;
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public MetadataStorageConsumer getConsumer() {
return consumer;
}
public void setConsumer(MetadataStorageConsumer consumer) {
this.consumer = consumer;
if (this.consumer != null)
this.consumer.addStrorage(getPrefix(), this);
}
}

View File

@ -0,0 +1,51 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.support;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class ExchangeEnricher implements Processor, MetadataStorageConsumer {
protected Map<MetadataStorage, String> map = new HashMap<>();
@Override
public void addStrorage(String prefix, MetadataStorage storage) {
this.map.put(storage, prefix);
}
@Override
public void process(Exchange exchange) throws Exception {
for (MetadataStorage ms: map.keySet()) {
Map<String, Object> allData = ms.getAllData();
String prefix = map.get(ms);
for (Entry<String, Object> entry: allData.entrySet()) {
exchange.getIn().setHeader(prefix + entry.getKey(), entry.getValue());
}
}
}
}

View File

@ -0,0 +1,34 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.support;
import java.util.Map;
public interface MetadataStorage {
Map<String, String> getStrings();
Map<String, Boolean> getBooleans();
Map<String, Number> getNumbers();
Map<String, Object> getAllData();
}

View File

@ -0,0 +1,26 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.support;
public interface MetadataStorageConsumer {
public void addStrorage(String prefix, MetadataStorage storage);
}

View File

@ -0,0 +1,47 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.support;
import java.util.Collections;
import java.util.Map;
public class MetadataStorageEmpty implements MetadataStorage {
@Override
public Map<String, String> getStrings() {
return Collections.emptyMap();
}
@Override
public Map<String, Boolean> getBooleans() {
return Collections.emptyMap();
}
@Override
public Map<String, Number> getNumbers() {
return Collections.emptyMap();
}
@Override
public Map<String, Object> getAllData() {
return Collections.emptyMap();
}
}

View File

@ -0,0 +1,68 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.support;
import java.util.HashMap;
import java.util.Map;
public class MetadataStorageImpl extends AbstractConsumerAwareMetadataStorage implements MetadataStorage {
protected Map<String, String> strings;
protected Map<String, Boolean> booleans;
protected Map<String, Number> numbers;
@Override
public Map<String, String> getStrings() {
return strings;
}
public void setStrings(Map<String, String> strings) {
this.strings = strings;
}
@Override
public Map<String, Boolean> getBooleans() {
return booleans;
}
public void setBooleans(Map<String, Boolean> booleans) {
this.booleans = booleans;
}
@Override
public Map<String, Number> getNumbers() {
return numbers;
}
public void setNumbers(Map<String, Number> numbers) {
this.numbers = numbers;
}
@Override
public Map<String, Object> getAllData() {
Map<String, Object> result = new HashMap<>();
result.putAll(strings);
result.putAll(booleans);
result.putAll(numbers);
return result;
}
}

View File

@ -0,0 +1,63 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.support;
import java.util.Map;
public class MetadataStorageWrapper extends AbstractConsumerAwareMetadataStorage implements MetadataStorage {
protected MetadataStorage origin;
protected MetadataStorage empty = new MetadataStorageEmpty();
public MetadataStorage getOrigin() {
return origin;
}
public void setOrigin(MetadataStorage origin) {
this.origin = origin;
}
protected MetadataStorage getStorage() {
if (origin != null)
return origin;
return empty;
}
@Override
public Map<String, String> getStrings() {
return getStorage().getStrings();
}
@Override
public Map<String, Boolean> getBooleans() {
return getStorage().getBooleans();
}
@Override
public Map<String, Number> getNumbers() {
return getStorage().getNumbers();
}
@Override
public Map<String, Object> getAllData() {
return getStorage().getAllData();
}
}

View File

@ -0,0 +1,224 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producer-core
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.wrapper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.CollectionType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.core.producer.wrapper.AbstractFactoryWrapper.GenerationProcessor;
@Component(service = GenerationProcessorService.class, immediate = true)
public class GenerationProcessorService {
private static final Logger log = LoggerFactory.getLogger(GenerationProcessorService.class);
public static final String FACTORY_PLUGIN_FIELD = "generation.plugins";
private static GenerationProcessorService INSTANCE;
public static GenerationProcessorService getInstance() {
return INSTANCE;
}
protected static enum PLUGIN_STATUS {
DENIED,
ALLOWED,
UNDEFINED
}
protected static class GenerationProcessorHelper {
ServiceReference<GenerationProcessor> ref;
String id;
List<String> factoryTypes = new ArrayList<>();
public GenerationProcessorHelper(ServiceReference<GenerationProcessor> ref) {
this.ref = ref;
this.id = getId(ref);
if (!CommonUtils.isValid(this.id))
return;
Object obj = ref.getProperty(GenerationProcessor.PROP_FACTORY_TYPE);
if (obj == null)
return;
if (obj instanceof String) {
factoryTypes.add(obj.toString());
return;
}
if (obj instanceof String[]) {
String[] data = (String[])obj;
factoryTypes.addAll(Arrays.asList(data));
}
if (obj instanceof List) {
for (Object item: (List)obj)
if (item!=null)
factoryTypes.add(item.toString());
}
}
public static String getId(ServiceReference<GenerationProcessor> ref) {
Object obj = ref.getProperty(GenerationProcessor.PROP_PROCESSOR_ID);
if (obj != null)
return obj.toString();
return null;
}
public PLUGIN_STATUS getStatusForType(String factoryType) {
PLUGIN_STATUS result = PLUGIN_STATUS.UNDEFINED;
for (String type: factoryTypes) {
boolean denied = type.startsWith("!");
if (denied)
type = type.substring(1);
if (matches(factoryType, type)) {
if (denied)
return PLUGIN_STATUS.DENIED;
else
result = PLUGIN_STATUS.ALLOWED;
}
}
return result;
}
protected boolean matches(String value, String template) {
String expression = template.replaceAll("\\*", ".*");
return Pattern.matches(expression, value);
}
}
Map<String, GenerationProcessorHelper> processors = new HashMap<>();
@Activate
public void activate() {
INSTANCE = this;
}
@Reference (unbind = "removeProcessor", cardinality = ReferenceCardinality.MULTIPLE
, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY
, service = GenerationProcessor.class, collectionType = CollectionType.REFERENCE)
public void addProcessor(ServiceReference<GenerationProcessor> ref) {
String id = GenerationProcessorHelper.getId(ref);
if (!CommonUtils.isValid(id))
return;
processors.put(id, new GenerationProcessorHelper(ref));
}
public void removeProcessor(ServiceReference<GenerationProcessor> ref) {
String id = GenerationProcessorHelper.getId(ref);
if (!CommonUtils.isValid(id))
return;
processors.remove(id);
}
protected PLUGIN_STATUS getEffectiveStatus(PLUGIN_STATUS st1, PLUGIN_STATUS st2) {
List<PLUGIN_STATUS> list = new ArrayList<>() {{
add(st1);
add(st2);
}};
if (list.contains(PLUGIN_STATUS.DENIED))
return PLUGIN_STATUS.DENIED;
if (list.contains(PLUGIN_STATUS.ALLOWED))
return PLUGIN_STATUS.ALLOWED;
return PLUGIN_STATUS.UNDEFINED;
}
public List<ServiceReference<GenerationProcessor>> getProcessorsRefs(EntaxyFactory factory){
List<ServiceReference<GenerationProcessor>> result = new ArrayList<>();
Map<String, PLUGIN_STATUS> factoryData = getStatusFromFactory(factory);
String type = factory.getType();
for (String pluginId: processors.keySet()) {
GenerationProcessorHelper helper = processors.get(pluginId);
PLUGIN_STATUS status = getEffectiveStatus(factoryData.get(pluginId)
, helper.getStatusForType(type));
if (PLUGIN_STATUS.ALLOWED.equals(status))
result.add(helper.ref);
}
return result;
}
protected Map<String, PLUGIN_STATUS> getStatusFromFactory(EntaxyFactory factory) {
Map<String, PLUGIN_STATUS> result = new HashMap<>();
Map<String, Object> typeInfo = factory.getTypeInfo();
if (typeInfo.containsKey(FACTORY_PLUGIN_FIELD)) {
List<String> plugins = new ArrayList<>();
Object obj = typeInfo.get(FACTORY_PLUGIN_FIELD);
if (obj != null) {
if (obj instanceof String)
plugins.add(obj.toString());
else if (obj instanceof Object[]) {
List<Object> objList = Arrays.asList((Object[])obj);
for (Object item: objList)
if (item!=null)
plugins.add(item.toString());
} else if (obj instanceof List)
for (Object item: (List)obj)
if (item != null)
plugins.add(item.toString());
}
for (String plugin: plugins) {
if (plugin.startsWith("!")) {
plugin = plugin.substring(1);
result.put(plugin, PLUGIN_STATUS.DENIED);
} else {
result.put(plugin, PLUGIN_STATUS.ALLOWED);
}
}
}
return result;
}
}

View File

@ -0,0 +1,19 @@
{
"*": {
"position": "inside_first"
},
"fragment": {
"isTransparent": true
},
"reference": {
"position": "inside_first",
"unique": ["id"],
"conflict": "ignore" /*[ignore, replace]*/
},
"route": {
"targetNodeName": "camelContext",
"position": "inside_last",
"createTargetNode": true,
"targetNodeXML": "<camelContext xmlns=\"http://camel.apache.org/schema/blueprint\" />"
}
}

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://www.apache.org/licenses/LICENSE-2.0
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.

View File

@ -0,0 +1,85 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
<artifactId>object-producing</artifactId>
<version>1.8.3</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.core.object-producing</groupId>
<artifactId>object-producing-resources-support</artifactId>
<packaging>bundle</packaging>
<name>ENTAXY :: PLATFORM :: CORE :: OBJECT PRODUCING :: RESOURCES SUPPORT</name>
<description>ENTAXY :: PLATFORM :: CORE :: OBJECT PRODUCING :: RESOURCES SUPPORT</description>
<properties>
<bundle.osgi.export.pkg>ru.entaxy.platform.core.producer.resources*</bundle.osgi.export.pkg>
</properties>
<dependencies>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.core.object-producing
</groupId>
<artifactId>object-producer-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.core.object-producing
</groupId>
<artifactId>object-producer-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.base.resources
</groupId>
<artifactId>resources-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.base.connecting.generator
</groupId>
<artifactId>generator-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.saxon</artifactId>
<version>${servicemix-saxon-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven-bundle-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Entaxy-Factory-Provider>true</Entaxy-Factory-Provider>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,37 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
import java.util.Map;
import ru.entaxy.platform.core.producer.resources.generator.GeneratedResourceWrapper;
public class DeployableResource extends ResourceDescriptor {
public Object resourceData;
public String resourceType;
public DeployableResource(Map<String, Object> properties) {
super(properties);
resourceData = properties.get(GeneratedResourceWrapper.OBJECT_KEY);
resourceType = properties.getOrDefault("type", "unknown").toString();
}
}

View File

@ -0,0 +1,31 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
import java.util.Map;
public interface EntaxyResourceProcessor {
String PROP_PROCESSOR = "processor";
String getName();
Object process(Object value, Map<String, Object> properties);
}

View File

@ -0,0 +1,28 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
import java.util.Map;
public interface EntaxyResourceProcessorService {
Object process(Object value, Map<String, Object> properties);
}

View File

@ -0,0 +1,28 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
public interface EntaxyResourceStringFormatter {
String getName();
String format(String value);
String unformat(String value);
}

View File

@ -0,0 +1,242 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.platform.base.objects.EntaxyObject;
import ru.entaxy.platform.base.objects.EntaxyObject.FIELDS;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.FACTORY;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.OUTPUTS;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.FieldInfo;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.JSONUtils;
import ru.entaxy.platform.core.producer.api.EntaxyProducerService;
import ru.entaxy.platform.core.producer.api.ExecutionPlan.ExecutionPlanUpdate;
import ru.entaxy.platform.core.producer.api.ProducerResult;
import ru.entaxy.platform.core.producer.api.ProducerResult.CommandResult;
import ru.entaxy.platform.core.producer.api.ProducingCommandExecutor;
import ru.entaxy.platform.core.producer.executor.AbstractCommandExecutor;
import ru.entaxy.platform.core.producer.executor.CommandExecutor;
import ru.entaxy.platform.core.producer.executor.objectmodel.Calculation;
import ru.entaxy.platform.core.producer.executor.objectmodel.FactoredObject;
import ru.entaxy.platform.core.producer.executor.objectmodel.FactoredObjectProxy;
import ru.entaxy.platform.core.producer.executor.objectmodel.ObjectModel;
@Component(service = ProducingCommandExecutor.class, immediate = true)
@CommandExecutor(id = "process-resources", predecessors = {"enrich"}, descendants = {"validate"})
public class ProcessResourcesCommand extends AbstractCommandExecutor implements ProducingCommandExecutor {
private static final Logger log = LoggerFactory.getLogger(ProcessResourcesCommand.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY)
EntaxyProducerService entaxyProducerServiceLocal;
@Reference(cardinality = ReferenceCardinality.MANDATORY)
EntaxyResourceService entaxyResourceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY)
ResourceDataProcessor resourceDataProcessor;
public ProcessResourcesCommand() {
super(null);
}
protected ProcessResourcesCommand(EntaxyProducerService entaxyProducerService) {
super(entaxyProducerService);
}
@Activate
public void activate(ComponentContext componentContext) {
this.entaxyProducerService = this.entaxyProducerServiceLocal;
this.entaxyProducerService.registerCommand(this);
}
@Override
protected boolean doExecute(ProducerResult currentResult, CommandResult commandResult,
Map<String, Object> instructions) throws Exception {
ObjectModel objectModel = currentResult.findResultObject(ObjectModel.class);
objectModel.startTracking();
JsonObject incomingJson = objectModel.getJsonCurrent().deepCopy();
for (FactoredObject fo: objectModel.objects) {
// skip proxies
if (fo instanceof FactoredObjectProxy)
continue;
String factoryId = fo.factoryId;
EntaxyFactory factory = entaxyProducerService.findFactoryById(factoryId);
JsonObject objectOrigin = fo.origin;
if (JSONUtils.setValue(objectOrigin, FIELDS.PROPERTIES, new JsonObject(), true)) {
printOutput("[DIRTY] CREATED 'properties' for [" + fo.getObjectId() + "/" + fo.getObjectType() + "]");
objectModel.setDirty();
}
JsonObject objectProperties = objectOrigin.get(FIELDS.PROPERTIES).getAsJsonObject();
String outputType = CommonUtils.isValid(fo.getOutputType())
?fo.getOutputType()
:factory.getDefaultOutput()!=null
?factory.getDefaultOutput().getType()
:OUTPUTS.OUTPUT_TYPE_INIT;
List<FieldInfo> factoryFields = factory.getFields(outputType);
log.debug("\n FIELDS FOR " + factory.getId() + "/" + outputType + ":" + factoryFields.size());
// if the value is JsonObject
// and represents some resource
// we first resolve it to actual value
JsonObject newProperties = new JsonObject();
for (Entry<String, JsonElement> entry: objectProperties.entrySet()) {
if (entry.getValue().isJsonObject())
if (entry.getValue().getAsJsonObject().has(ResourceDataProcessor.ENTAXY_RESOURCE_KEY)) {
JsonElement jsonDescriptor = entry.getValue().getAsJsonObject().get(ResourceDataProcessor.ENTAXY_RESOURCE_KEY);
ResourceDescriptor resourceDescriptor = ResourceDescriptor.fromJson(jsonDescriptor);
if (resourceDescriptor == null)
continue;
Object newData = resourceDataProcessor.getResourceDataFromDescriptor(resourceDescriptor);
JsonElement newValue = (new Gson()).toJsonTree(newData);
newProperties.add(entry.getKey(), newValue);
}
}
for (Entry<String, JsonElement> entry: newProperties.entrySet()) {
if (JSONUtils.setValue(objectProperties, entry.getKey(), entry.getValue().deepCopy(), false)) {
printOutput("[DIRTY] UPDATED " + entry.getKey() + " for [" + fo.getObjectId() + "/" + fo.getObjectType() + "]");
objectModel.setDirty();
}
}
// for the field defined as a resource
// we must make an object
for (FieldInfo fi: factoryFields) {
log.debug("\n--> FIELD :: " + fi.getName());
log.debug("\n" + objectProperties.toString());
JsonObject jsonFi = fi.getJsonOrigin();
if (!objectProperties.has(fi.getName()))
continue;
log.debug("\nORIGIN:\n" + fi.getJsonOrigin().toString());
if (jsonFi.has(ResourceDataProcessor.ENTAXY_RESOURCE_KEY)) {
log.debug("\n--> FIELD :: " + fi.getName() + " IS A RESOURCE");
ResourceDescriptor descriptor = ResourceDescriptor.fromJson(jsonFi.get(ResourceDataProcessor.ENTAXY_RESOURCE_KEY));
if (descriptor == null)
continue;
JsonElement currentValue = objectProperties.get(fi.getName());
if (currentValue.isJsonObject()) {
JsonObject currentObject = currentValue.getAsJsonObject();
if (currentObject.has("isRef")) {
continue;
}
}
JsonElement newValueElement = jsonFi.get(ResourceDataProcessor.ENTAXY_RESOURCE_KEY);
if (!newValueElement.isJsonObject())
continue;
JsonObject properties = newValueElement.getAsJsonObject().deepCopy();
// add default location if not set
if (!properties.has(ResourceDataProcessor.PROP_LOCATION)) {
JsonObject locationData = new JsonObject();
locationData.addProperty(Calculation.FIELD_IS_CALCULATED, true);
locationData.addProperty("lazy", true);
locationData.addProperty("expression"
, "object-resources/${#OWNER#.objectId}/" + fi.getName() + "." + fi.getType().split(":")[0]);
properties.add(ResourceDataProcessor.PROP_LOCATION, locationData);
}
properties.add("content", currentValue);
properties.addProperty("type", fi.getType());
JsonObject newValue = new JsonObject();
newValue.addProperty(FACTORY.TYPE, "entaxy.resource");
newValue.addProperty(EntaxyObject.FIELDS.FACTORY_ID, "entaxy-resource");
JsonObject refConfig = new JsonObject();
refConfig.addProperty(EntaxyObject.FIELDS.REF_FIELD, "content");
refConfig.addProperty("generated.targetType", Generated.GENERATED_TYPE_BLUEPRINT_FRAGMENT);
newValue.add("refConfig", refConfig);
// newValue.addProperty("__skip", true);
newValue.add(FIELDS.PROPERTIES, properties);
if (jsonFi.has("config") && jsonFi.get("config").isJsonObject()) {
JsonObject configObject = jsonFi.get("config").getAsJsonObject();
for (Entry<String, JsonElement> entry: configObject.entrySet()) {
if (!newValue.has(entry.getKey()))
newValue.add(entry.getKey(), entry.getValue().deepCopy());
}
}
JSONUtils.setValue(objectProperties, fi.getName(), newValue, false);
objectModel.setDirty();
}
}
}
if (objectModel.stopTracking()) {
// remove ##embedded
for (FactoredObject fo: objectModel.objects)
fo.origin.remove(FactoredObject.EMBEDDED_FIELD);
commandResult.planUpdate = ExecutionPlanUpdate.create()
// .updateInstructions().target("enrich").value("skip", true).complete()
.reset().target("analyze").complete();
}
JsonObject outgoingJson = objectModel.getJsonCurrent();
printOutput("\n== INCOMING JSON ==\n");
printOutput(incomingJson.toString());
printOutput("\n== OUTGOING JSON ==\n");
printOutput(outgoingJson.toString());
commandResult.resultObject(outgoingJson);
return true;
}
}

View File

@ -0,0 +1,35 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
import ru.entaxy.platform.core.producer.api.EntaxyFactoryDataProcessor;
public interface ResourceDataProcessor extends EntaxyFactoryDataProcessor {
String ENTAXY_RESOURCE_KEY = ResourceProducer.DIRECTIVES.RESOURCE;
String PROP_PROVIDER = "provider";
String PROP_LOCATION = "location";
String PROP_END_TYPE = "endType";
String PROP_FORMAT = "format";
Object getResourceDataFromDescriptor(ResourceDescriptor descriptor);
}

View File

@ -0,0 +1,90 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
import java.util.Map;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.platform.base.support.CommonUtils;
public class ResourceDescriptor {
static public final String RESOURCE_TYPE_PREFIX = "resource:";
public static ResourceDescriptor fromJson(JsonElement element) {
if (element == null)
return null;
if (!element.isJsonObject())
return null;
return new ResourceDescriptor(element.getAsJsonObject());
}
public static ResourceDescriptor fromMap(Map<String, Object> properties) {
return new ResourceDescriptor(properties);
}
protected JsonObject origin;
public String provider;
public String location;
public String endType;
public String format;
public ResourceDescriptor(JsonObject jsonObject) {
this.origin = jsonObject;
loadData();
}
public ResourceDescriptor(Map<String, Object> properties) {
this.origin = new JsonObject();
loadDataFromMap(properties);
}
protected void loadData() {
if (this.origin.has(ResourceDataProcessor.PROP_PROVIDER))
this.provider = this.origin.get(ResourceDataProcessor.PROP_PROVIDER).getAsString();
if (this.origin.has(ResourceDataProcessor.PROP_LOCATION))
if (this.origin.get(ResourceDataProcessor.PROP_LOCATION).isJsonPrimitive())
this.location = this.origin.get(ResourceDataProcessor.PROP_LOCATION).getAsString();
if (this.origin.has(ResourceDataProcessor.PROP_END_TYPE))
this.endType = this.origin.get(ResourceDataProcessor.PROP_END_TYPE).getAsString();
if (this.origin.has(ResourceDataProcessor.PROP_FORMAT))
this.format = this.origin.get(ResourceDataProcessor.PROP_FORMAT).getAsString();
}
protected void loadDataFromMap(Map<String, Object> properties) {
this.provider = properties.getOrDefault(ResourceDataProcessor.PROP_PROVIDER, "default").toString();
this.location = properties.getOrDefault(ResourceDataProcessor.PROP_LOCATION, "").toString();
this.endType = properties.getOrDefault(ResourceDataProcessor.PROP_END_TYPE, "").toString();
this.format = properties.getOrDefault(ResourceDataProcessor.PROP_FORMAT, "").toString();
};
public String getResourceUrl() {
return (CommonUtils.isValid(provider)?provider+":":"") + location;
}
public boolean isReturnResource() {
return !CommonUtils.isValid(endType) || "resource".equalsIgnoreCase(endType);
}
}

View File

@ -0,0 +1,113 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
import java.io.InputStream;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.io.IOUtils;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
import ru.entaxy.esb.resources.EntaxyResource;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.platform.core.producer.executor.builder.BuiltObject;
import ru.entaxy.platform.core.producer.executor.builder.DefaultBuiltObject;
import ru.entaxy.platform.core.producer.executor.builder.ObjectBuilder;
import ru.entaxy.platform.core.producer.executor.deployer.DeployedObject;
import ru.entaxy.platform.core.producer.executor.deployer.ObjectDeployer;
import ru.entaxy.platform.core.producer.executor.support.LocalPrintOutput;
@Component(service = {ObjectBuilder.class, ObjectDeployer.class})
public class ResourceObjectSupport implements ObjectBuilder, ObjectDeployer {
@Reference (cardinality = ReferenceCardinality.MANDATORY)
EntaxyResourceService entaxyResourceService;
/*
* ObjectBuilder
*/
@Override
public boolean isBuildable(Generated generated) {
return generated.getType().startsWith(ResourceDescriptor.RESOURCE_TYPE_PREFIX);
}
@Override
public BuiltObject build(Generated generated, Map<String, Object> instructions) throws Exception {
if (!isBuildable(generated))
return null;
LocalPrintOutput printer = new LocalPrintOutput(instructions);
printer.printOutput(" = GENERATED PROPERTIES");
for (Entry<String, Object> entry: generated.getProperties().entrySet()) {
printer.printOutput(" :: " + entry.getKey() + " = [\n"
+ (entry.getValue()==null?"":entry.getValue().toString())
+ "\n]");
}
printer.printOutput(" = /GENERATED PROPERTIES");
return new DefaultBuiltObject(new DeployableResource(generated.getProperties()));
}
/*
* ObjectDeployer
*/
@Override
public boolean isDeployable(BuiltObject object) {
return object.getObject() instanceof DeployableResource;
}
@Override
public DeployedObject deploy(BuiltObject object, Map<String, Object> instructions) throws Exception {
if (!isDeployable(object))
return null;
LocalPrintOutput printer = new LocalPrintOutput(instructions);
DeployableResource dr = (DeployableResource)object.getObject();
printer.printOutput(" = RESOURCE TO DEPLOY");
printer.printOutput(dr.getResourceUrl() + " [" + dr.resourceType + "/" + dr.endType + "]");
EntaxyResource resource = entaxyResourceService.getResource(dr.getResourceUrl());
resource.save(getInputStream(dr));
printer.printOutput(" :: DEPLOYED");
// nothing to do with resource in further phases
return null;
}
protected InputStream getInputStream(DeployableResource res) {
if ((res==null) || (res.resourceData == null))
return getDefaultInputStream();
if ("String".equals(res.endType))
return IOUtils.toInputStream(res.resourceData.toString());
// TODO support other resource types
return getDefaultInputStream();
}
protected InputStream getDefaultInputStream() {
return IOUtils.toInputStream("");
}
}

View File

@ -0,0 +1,64 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
import org.osgi.service.component.annotations.CollectionType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
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.core.producer.api.EntaxyProducer;
import ru.entaxy.platform.core.producer.impl.CommonObjectProducer;
import ru.entaxy.platform.core.producer.impl.EntaxyProducerInfo;
import ru.entaxy.platform.core.producer.wrapper.AbstractFactoryWrapper;
import ru.entaxy.platform.core.producer.wrapper.DefaultFactoryWrapper;
@Component(service = {EntaxyProducer.class}, immediate = true)
@EntaxyProducerInfo(supportedTypes = {"entaxy.resource"})
public class ResourceProducer extends CommonObjectProducer implements EntaxyProducer {
public static interface DIRECTIVES {
String RESOURCE = "@RESOURCE";
}
public static final String PROP_CONTENT = "content";
public static final String PROP_PREPROCESS = "preprocess";
@Reference(bind = "addFactory", unbind = "removeFactory", cardinality = ReferenceCardinality.MULTIPLE
, collectionType = CollectionType.SERVICE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
public void addFactory(EntaxyFactory factory) {
doAddFactory(factory);
}
// WE MUST DECLARE IT for @Reference annotation processor
@Override
public void removeFactory(EntaxyFactory factory) {
super.removeFactory(factory);
}
@Override
protected AbstractFactoryWrapper doAddFactory(EntaxyFactory factory) {
return super.doAddFactory(factory, DefaultFactoryWrapper.class);
}
}

View File

@ -0,0 +1,27 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources;
public interface StringFormatterService {
String format(String value, String[] formatters);
String unformat(String value, String[] formatters);
}

View File

@ -0,0 +1,46 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources.formatters;
import java.util.Base64;
import org.osgi.service.component.annotations.Component;
import ru.entaxy.platform.core.producer.resources.EntaxyResourceStringFormatter;
@Component (service = EntaxyResourceStringFormatter.class, immediate = true)
public class Base64Formatter implements EntaxyResourceStringFormatter {
@Override
public String getName() {
return "base64";
}
@Override
public String format(String value) {
return new String(Base64.getEncoder().encode(value.getBytes()));
}
@Override
public String unformat(String value) {
return new String(Base64.getDecoder().decode(value));
}
}

View File

@ -0,0 +1,54 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources.generator;
import java.util.HashMap;
import java.util.Map;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
import ru.entaxy.platform.core.producer.resources.ResourceDescriptor;
public class GeneratedResourceWrapper implements Generated {
public static final String OBJECT_KEY = "#_object";
protected Map<String, Object> properties = new HashMap<>();
public GeneratedResourceWrapper (Map<String, Object> props) {
this.properties.putAll(props);
}
@Override
public String getType() {
return this.properties.getOrDefault("generated.targetType",
ResourceDescriptor.RESOURCE_TYPE_PREFIX + properties.getOrDefault("type", "unknown")).toString();
}
@Override
public Object getObject() {
return this.properties.get(OBJECT_KEY);
}
@Override
public Map<String, Object> getProperties() {
return this.properties;
}
}

View File

@ -0,0 +1,131 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources.generator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.ArrayUtils;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.AbstractSelfPublishGenerator;
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.GeneratorService;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.factory.GeneratorFactory;
import ru.entaxy.esb.resources.EntaxyResource;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessorService;
import ru.entaxy.platform.core.producer.resources.ResourceDataProcessor;
import ru.entaxy.platform.core.producer.resources.ResourceDescriptor;
import ru.entaxy.platform.core.producer.resources.ResourceProducer;
import ru.entaxy.platform.core.producer.resources.StringFormatterService;
@Component(
service = {GeneratorService.class},
property = {GeneratorService.PROP_GENERATOR_TYPE + "=" + ResourceWrapGenerator.GENERATOR_NAME},
immediate = true
)
public class ResourceWrapGenerator extends AbstractSelfPublishGenerator<ResourceWrapGenerator>
implements Generator {
public static final String GENERATOR_NAME = "resource-wrap";
protected static EntaxyResourceService ENTAXY_RESOURCE_SERVICE;
protected static StringFormatterService STRING_FORMATTER_SERVICE;
protected static EntaxyResourceProcessorService RESOURCE_PROCESSOR_SERVICE;
@Reference (cardinality = ReferenceCardinality.MANDATORY)
EntaxyResourceService entaxyResourceService;
@Reference (cardinality = ReferenceCardinality.MANDATORY)
StringFormatterService stringFormatterService;
@Reference (cardinality = ReferenceCardinality.MANDATORY)
EntaxyResourceProcessorService entaxyResourceProcessorService;
@Activate
public void activate() {
GeneratorFactory.register(ResourceWrapGenerator.GENERATOR_NAME, this);
ResourceWrapGenerator.ENTAXY_RESOURCE_SERVICE = entaxyResourceService;
ResourceWrapGenerator.STRING_FORMATTER_SERVICE = stringFormatterService;
ResourceWrapGenerator.RESOURCE_PROCESSOR_SERVICE = entaxyResourceProcessorService;
}
@Deactivate
public void deactivate() {
GeneratorFactory.unregister(GENERATOR_NAME);
}
@Override
public Generated generate(Map<String, Object> properties) throws Exception {
ResourceDescriptor descriptor = ResourceDescriptor.fromMap(properties);
String content = null;
String object = null;
if (properties.containsKey(ResourceProducer.PROP_CONTENT)) {
content = properties.get(ResourceProducer.PROP_CONTENT).toString();
String[] formatters = descriptor.format.split(",");
ArrayUtils.reverse(formatters);
object = STRING_FORMATTER_SERVICE.unformat(content, formatters);
if (properties.containsKey(ResourceProducer.PROP_PREPROCESS)) {
Object pp = properties.get(ResourceProducer.PROP_PREPROCESS);
if (pp instanceof List) {
List list = (List)pp;
for (Object obj: list) {
if (obj instanceof Map) {
Object result = RESOURCE_PROCESSOR_SERVICE.process(object, (Map<String, Object>)obj);
if (result != null)
object = result.toString();
else
object = "";
}
}
}
}
} else {
EntaxyResource resource = ENTAXY_RESOURCE_SERVICE.getResource(descriptor.getResourceUrl());
if (resource.exists()) {
object = resource.getAsString();
content = STRING_FORMATTER_SERVICE.format(object, descriptor.format.split(","));
}
}
if (object == null)
return null;
Map<String, Object> resultMap = new HashMap<>();
resultMap.putAll(properties);
resultMap.put(ResourceProducer.PROP_CONTENT, content);
resultMap.put("#_object", object);
return new GeneratedResourceWrapper(resultMap);
}
@Override
public boolean isGeneratable(Map<String, Object> properties) throws Exception {
return properties.containsKey(ResourceDataProcessor.PROP_PROVIDER)
&& properties.containsKey(ResourceDataProcessor.PROP_LOCATION);
}
}

View File

@ -0,0 +1,84 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources.impl;
import java.util.HashMap;
import java.util.Map;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.CollectionType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessor;
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessorService;
@Component (service = EntaxyResourceProcessorService.class, immediate = true)
public class EntaxyResourceProcessorServiceImpl implements EntaxyResourceProcessorService {
private static final Logger log = LoggerFactory.getLogger(EntaxyResourceProcessorServiceImpl.class);
protected static EntaxyResourceProcessorService _INSTANCE;
public static EntaxyResourceProcessorService getInstance() {
return _INSTANCE;
}
protected Map<String, EntaxyResourceProcessor> processorsMap = new HashMap<>();
@Activate
public void activate() {
_INSTANCE = this;
}
@Reference (cardinality = ReferenceCardinality.MULTIPLE, collectionType = CollectionType.SERVICE, policy = ReferencePolicy.DYNAMIC
, policyOption = ReferencePolicyOption.GREEDY, unbind = "removeProcessor")
public void addProcessor(EntaxyResourceProcessor processor) {
synchronized (processorsMap) {
this.processorsMap.put(processor.getName(), processor);
}
}
public void removeProcessor(EntaxyResourceProcessor processor) {
synchronized (processorsMap) {
this.processorsMap.remove(processor.getName());
}
}
@Override
public Object process(Object value, Map<String, Object> properties) {
Object val = properties.get(EntaxyResourceProcessor.PROP_PROCESSOR);
if (val == null)
return value;
String processorName = val.toString();
if (!processorsMap.containsKey(processorName)) {
log.warn("Unknown processor [{}] in [{}]", processorName, properties);
return value;
}
return processorsMap.get(processorName).process(value, properties);
}
}

View File

@ -0,0 +1,111 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources.impl;
import java.util.Map;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.esb.resources.EntaxyResource;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.core.producer.api.EntaxyFactoryDataProcessor;
import ru.entaxy.platform.core.producer.resources.ResourceDataProcessor;
import ru.entaxy.platform.core.producer.resources.ResourceDescriptor;
import ru.entaxy.platform.core.producer.resources.StringFormatterService;
@Component (service = {EntaxyFactoryDataProcessor.class, ResourceDataProcessor.class}, immediate = true)
public class ResourceDataProcessorImpl implements EntaxyFactoryDataProcessor, ResourceDataProcessor {
private static final Logger log = LoggerFactory.getLogger(ResourceDataProcessorImpl.class);
@Reference (cardinality = ReferenceCardinality.MANDATORY)
EntaxyResourceService entaxyResourceService;
@Reference (cardinality = ReferenceCardinality.MANDATORY)
StringFormatterService stringFormatterService;
@Override
public Object processDefaultValue(Object currentValue) {
// log.info("\n-->> PROCESSING :: " + (currentValue==null?"NULL":currentValue.getClass().getName()));
if (currentValue == null)
return currentValue;
ResourceDescriptor descriptor = null;
if (currentValue instanceof JsonElement) {
// log.info("\n-->> PROCESSING :: JsonElement");
if (((JsonElement) currentValue).isJsonObject()) {
// log.info("\n-->> PROCESSING :: JsonObject");
JsonObject jsonObject = ((JsonElement) currentValue).getAsJsonObject();
if (jsonObject.has(ENTAXY_RESOURCE_KEY)) {
// log.info("\n-->> PROCESSING :: entaxy-resource");
descriptor = ResourceDescriptor.fromJson(jsonObject.get(ENTAXY_RESOURCE_KEY));
}
}
} else if (currentValue instanceof Map) {
// log.info("\n-->> PROCESSING :: MAP");
if (((Map)currentValue).containsKey(ENTAXY_RESOURCE_KEY)) {
Object current = ((Map)currentValue).get(ENTAXY_RESOURCE_KEY);
// log.info("\n-->> PROCESSING :: SUBMAP :: " + current.getClass().getName());
if (current instanceof Map) {
JsonElement je = (new Gson()).toJsonTree(current);
// log.info("\n-->> PROCESSING :: JE :: " + je.toString());
descriptor = ResourceDescriptor.fromJson(je);
}
}
} else {
// log.info("\n-->> PROCESSING :: NOT KNOWN");
}
if (descriptor != null) {
Object result = getResourceDataFromDescriptor(descriptor);
return result==null?currentValue:result;
}
return currentValue;
}
@Override
public Object getResourceDataFromDescriptor(ResourceDescriptor descriptor) {
EntaxyResource resource = entaxyResourceService.getResource(descriptor.getResourceUrl());
if (resource == null)
return null;
if (descriptor.isReturnResource())
return resource;
if (!resource.exists())
return null;
if ("String".equalsIgnoreCase(descriptor.endType)) {
String resourceData = resource.getAsString();
String format = descriptor.format;
if (CommonUtils.isValid(format)) {
log.info("\n FORMAT :: " + format);
resourceData = stringFormatterService.format(resourceData, format.split(","));
}
return resourceData;
}
return resource.getLocation();
}
}

View File

@ -0,0 +1,88 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.CollectionType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import ru.entaxy.platform.core.producer.resources.EntaxyResourceStringFormatter;
import ru.entaxy.platform.core.producer.resources.StringFormatterService;
@Component (service = StringFormatterService.class, immediate = true)
public class StringFormatterServiceImpl implements StringFormatterService {
protected static StringFormatterService _INSTANCE;
public static StringFormatterService getInstance() {
return _INSTANCE;
}
protected Map<String, EntaxyResourceStringFormatter> formattersMap = new HashMap<>();
@Activate
public void activate() {
_INSTANCE = this;
}
@Reference (cardinality = ReferenceCardinality.MULTIPLE, collectionType = CollectionType.SERVICE, policy = ReferencePolicy.DYNAMIC
, policyOption = ReferencePolicyOption.GREEDY, unbind = "removeFormatter")
public void addFormatter(EntaxyResourceStringFormatter formatter) {
synchronized (formattersMap) {
this.formattersMap.put(formatter.getName(), formatter);
}
}
public void removeFormatter(EntaxyResourceStringFormatter formatter) {
synchronized (formattersMap) {
this.formattersMap.remove(formatter.getName());
}
}
@Override
public String format(String value, String[] formatters) {
String current = value;
for (int i=0; i<formatters.length; i++) {
String formatter = formatters[i].trim();
if (this.formattersMap.containsKey(formatter))
current = this.formattersMap.get(formatter).format(current);
}
return current;
}
@Override
public String unformat(String value, String[] formatters) {
String current = value;
for (int i=0; i<formatters.length; i++) {
String formatter = formatters[i].trim();
if (this.formattersMap.containsKey(formatter))
current = this.formattersMap.get(formatter).unformat(current);
}
return current;
}
}

View File

@ -0,0 +1,131 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources.processors;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ru.entaxy.esb.resources.EntaxyResource;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.xml.CommonXMLUtils;
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessor;
@Component (service = EntaxyResourceProcessor.class, immediate = true)
public class MergeResourceProcessor implements EntaxyResourceProcessor {
private static final Logger log = LoggerFactory.getLogger(MergeResourceProcessor.class);
public static final String PROP_SOURCE = "source";
public static final String PROP_SOURCE_ELEMENT = "sourceElement";
public static final String PROP_TARGET_ELEMENT = "targetElement";
@Reference(cardinality = ReferenceCardinality.MANDATORY)
EntaxyResourceService entaxyResourceService;
@Override
public String getName() {
return "merge";
}
@Override
public Object process(Object value, Map<String, Object> properties) {
if (value == null)
return value;
Object valueToReturn = null;
String sourceLocation = properties.getOrDefault(PROP_SOURCE, "").toString();
if (!CommonUtils.isValid(sourceLocation)) {
log.warn("'source' not defined in [{}]", properties);
return value;
}
EntaxyResource resource = entaxyResourceService.getResource(sourceLocation);
if (!resource.exists()) {
log.warn("Source [{}] not found, was defined in [{}]", sourceLocation, properties);
return value;
}
String sourceElement = properties.getOrDefault(PROP_SOURCE_ELEMENT, "").toString();
if (!CommonUtils.isValid(sourceElement)) {
log.warn("Source element not defined in [{}]", properties);
return value;
}
String targetElement = properties.getOrDefault(PROP_TARGET_ELEMENT, "").toString();
if (!CommonUtils.isValid(targetElement)) {
log.warn("Source element not defined in [{}]", properties);
return value;
}
String targetXMLString = value.toString();
String sourceXMLString = resource.getAsString();
try {
Document targetDocument = CommonXMLUtils.parseString(false, targetXMLString);
Document sourceDocument = CommonXMLUtils.parseString(false, sourceXMLString);
NodeList nodesToReplace = targetDocument.getElementsByTagName(targetElement);
if (nodesToReplace.getLength() == 0)
return value;
NodeList replacements = sourceDocument.getElementsByTagName(sourceElement);
if (replacements.getLength() == 0)
return value;
Node replacement = replacements.item(0);
NodeList replacementChildren = replacement.getChildNodes();
List<Node> toRemove = new ArrayList<>();
for (int i=0; i<nodesToReplace.getLength(); i++) {
Node toReplace = nodesToReplace.item(i);
for (int j=0; j<replacementChildren.getLength(); j++) {
Node adopted = targetDocument.adoptNode(replacementChildren.item(j).cloneNode(true));
toReplace.getParentNode().insertBefore(adopted, toReplace);
}
toRemove.add(toReplace);
}
for (Node n: toRemove)
n.getParentNode().removeChild(n);
valueToReturn = CommonXMLUtils.doc2string(targetDocument);
} catch (Exception e) {
log.error("Error merging documents", e);
return value;
}
return valueToReturn;
}
}

View File

@ -0,0 +1,113 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources.processors;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Map;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.resources.EntaxyResource;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessor;
@Component (service = EntaxyResourceProcessor.class, immediate = true)
public class XSLTResourceProcessor implements EntaxyResourceProcessor {
public static final String PROP_SOURCE = "source";
public static final String PROP_PARAMETERS = "parameters";
private static final Logger log = LoggerFactory.getLogger(XSLTResourceProcessor.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY)
EntaxyResourceService entaxyResourceService;
@Override
public String getName() {
return "xslt";
}
@Override
public Object process(Object value, Map<String, Object> properties) {
log.info("XSLT :: processing [{}]", value);
if (value == null)
return value;
String xsltLocation = properties.getOrDefault(PROP_SOURCE, "").toString();
if (!CommonUtils.isValid(xsltLocation)) {
log.warn("XSL not defined in [{}]", properties);
return value;
}
EntaxyResource resource = entaxyResourceService.getResource(xsltLocation);
if (!resource.exists()) {
log.warn("XSL [{}] not found, was defined in [{}]", xsltLocation, properties);
return value;
}
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
TransformerFactory factory = TransformerFactory.newInstance();
Source xslt = new StreamSource(resource.getInputStream());
Transformer transformer;
try {
transformer = factory.newTransformer(xslt);
} catch (TransformerConfigurationException e) {
log.error("Error creating transformer for [" + xsltLocation + "]", e);
return value;
}
if (properties.containsKey(PROP_PARAMETERS)) {
Object obj = properties.get(PROP_PARAMETERS);
if (obj instanceof Map) {
Map<String, Object> map = (Map<String, Object>)obj;
for (Map.Entry<String, Object> entry: map.entrySet()) {
transformer.setParameter(entry.getKey(), entry.getValue());
}
}
}
Source xml = new StreamSource(new StringReader(value.toString()));
StringWriter result = new StringWriter();
try {
transformer.transform(xml, new StreamResult(result));
} catch (TransformerException e) {
log.error("Error transforming [" + value.toString() + "] with [" + xsltLocation + "]", e);
return value;
}
return result.toString();
}
}

View File

@ -0,0 +1,136 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-resources-support
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.resources.processors;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Map;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XdmAtomicValue;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;
import ru.entaxy.esb.resources.EntaxyResource;
import ru.entaxy.esb.resources.EntaxyResourceService;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessor;
@Component (service = EntaxyResourceProcessor.class, immediate = true)
public class XSLTSaxonResourceProcessor implements EntaxyResourceProcessor {
public static final String PROP_SOURCE = "source";
public static final String PROP_PARAMETERS = "parameters";
private static final Logger log = LoggerFactory.getLogger(XSLTSaxonResourceProcessor.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY)
EntaxyResourceService entaxyResourceService;
@Override
public String getName() {
return "saxon";
}
@Override
public Object process(Object value, Map<String, Object> properties) {
log.info("SAXON :: processing [{}]", value);
if (value == null)
return value;
String xsltLocation = properties.getOrDefault(PROP_SOURCE, "").toString();
if (!CommonUtils.isValid(xsltLocation)) {
log.warn("XSL not defined in [{}]", properties);
return value;
}
EntaxyResource resource = entaxyResourceService.getResource(xsltLocation);
if (!resource.exists()) {
log.warn("XSL [{}] not found, was defined in [{}]", xsltLocation, properties);
return value;
}
Processor processor = new Processor(false);
XsltCompiler compiler = processor.newXsltCompiler();
XsltExecutable stylesheet;
StringWriter result = new StringWriter();
try {
compiler.setErrorListener(new ErrorListener() {
@Override
public void warning(TransformerException exception) throws TransformerException {
log.warn("SAXON COMPILER:", exception);
}
@Override
public void fatalError(TransformerException exception) throws TransformerException {
log.error("SAXON COMPILER:", exception);
}
@Override
public void error(TransformerException exception) throws TransformerException {
log.error("SAXON COMPILER:", exception);
}
});
stylesheet = compiler.compile(new StreamSource(resource.getInputStream()));
Serializer out = processor.newSerializer(result);
out.setOutputProperty(Serializer.Property.METHOD, "xml");
out.setOutputProperty(Serializer.Property.INDENT, "yes");
XsltTransformer transformer = stylesheet.load();
Source xml = new StreamSource(new StringReader(value.toString()));
transformer.setSource(xml);
transformer.setDestination(out);
if (properties.containsKey(PROP_PARAMETERS)) {
Object obj = properties.get(PROP_PARAMETERS);
if (obj instanceof Map) {
Map<String, Object> map = (Map<String, Object>)obj;
for (Map.Entry<String, Object> entry: map.entrySet()) {
transformer.setParameter(
new QName(entry.getKey())
, new XdmAtomicValue(entry.getValue().toString()));
}
}
}
transformer.transform();
} catch (SaxonApiException e) {
log.error("Error transforming [" + value.toString() + "] with [" + xsltLocation + "]", e);
return value;
}
return result.toString();
}
}

View File

@ -0,0 +1,17 @@
{
"factory": {
"id": "entaxy-resource",
"type": "entaxy.resource"
},
"entaxy.resource": {},
"outputs": {
"init": {
"isDefault": true,
"generator": "resource-wrap"
},
"ref": {
"generator": "resource-wrap",
"scopes": ["private", "public"]
}
}
}

View File

@ -0,0 +1,38 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-shell
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.shell;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.lifecycle.Service;
@Service
@Command(scope = EntaxyProducerServiceSupport.SCOPE, name = "factory-configuration")
public class FactoryConfiguration extends FactoryAwareCommand {
@Override
protected Object doExecute() throws Exception {
// OUTPUT TO SHELL
System.out.println(entaxyFactory.getJsonConfiguration());
return null;
}
}

View File

@ -0,0 +1,77 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-shell
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.shell;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.karaf.shell.api.action.Action;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.apache.karaf.shell.support.table.ShellTable;
import ru.entaxy.platform.base.objects.factory.tracker.TrackedFactoryManager;
import ru.entaxy.platform.base.objects.factory.tracker.TrackedFactoryManager.TrackedManagedFactory;
@Service
@Command(scope = EntaxyProducerServiceSupport.SCOPE, name = "factory-manager-status")
public class FactoryManagerStatus implements Action {
@Reference
TrackedFactoryManager factoryManager;
@Override
public Object execute() throws Exception {
ShellTable table = new ShellTable();
table.column("ID");
table.column("Active");
table.column("Consistent");
table.column("Up2date");
table.column("Parent");
table.column("Requires");
for (TrackedManagedFactory tmf: factoryManager.getManagedFactories()) {
final List<String> waiting = tmf.waitingFor;
table.addRow().addContent(
tmf.factoryId
, tmf.isActive?"*":""
, tmf.isConsistent()?"*":""
, tmf.isUpToDate?"*":""
, decorate(tmf.parent, waiting)
, tmf.requirements.stream().map(s -> decorate(s, waiting))
.collect(Collectors.joining(","))
);
}
// OUTPUT TO SHELL
table.print(System.out);
return null;
}
protected String decorate(String test, List<String> values) {
if (values.contains(test))
return "*" + test;
return test;
}
}

View File

@ -0,0 +1,53 @@
/*-
* ~~~~~~licensing~~~~~~
* object-producing-shell
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.core.producer.shell;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.apache.karaf.shell.support.table.ShellTable;
@Service
@Command(scope = EntaxyProducerServiceSupport.SCOPE, name = "factory-type-info")
public class FactoryTypeInfo extends FactoryAwareCommand {
@Override
protected Object doExecute() throws Exception {
ShellTable table = new ShellTable();
table.column("Name");
table.column("Value");
Map<String, Object> typeInfo = entaxyFactory.getTypeInfo();
for (Entry<String, Object> entry: typeInfo.entrySet()) {
table.addRow().addContent(
entry.getKey(),
entry.getValue()==null?"":entry.getValue().toString()
);
}
table.print(System.out);
return null;
}
}

View File

@ -0,0 +1,54 @@
{
"factory": {
"id": "abstract-connection",
"type": "entaxy.runtime.connection",
"isAbstract": true,
"description": "Factory abstract-connection of entaxy.runtime.connection"
},
"entaxy.runtime.connection": {
/* BOTH, CONSUMER_ONLY, PRODUCER_ONLY */
"modeSupported": "BOTH"
},
"fields": {
"##publishRelation": {
"type": "String",
"isHidden": true,
"required": true,
"defaultValue": {
"@CALCULATED": {
"expression": "${#OWNER#.objectId}:${#OWNER#.type}:connection:connections",
"targetPath": "$.properties.##publish.relation",
"removeResolved": true,
"lazy": true
}
}
}
},
"outputs": {
"init": {
"isDefault": false,
"fields": {
"##publishRelation": {
"@SCOPED": ["private"]
}
},
"config": {
"configurable": false
},
"scopes": [
"public",
"private"
]
},
"ref": {
"isDefault": false,
"config": {
"configurable": false
},
"scopes": [
"public",
"private"
]
}
}
}

View File

@ -0,0 +1,29 @@
[#ftl attributes={"generated.type":"blueprint.fragment"}]
[#--
~~~~~~licensing~~~~~~
connection-producing
==========
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
http://www.apache.org/licenses/LICENSE-2.0
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.
~~~~~~/licensing~~~~~~
--]
<!--
factoryId: abstract-connection
factoryType: entaxy.runtime.connection
outputType: init
-->

View File

@ -0,0 +1,24 @@
[#ftl attributes={"generated.type":"blueprint.fragment"}]
[#--
~~~~~~licensing~~~~~~
connection-producing
==========
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
http://www.apache.org/licenses/LICENSE-2.0
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.
~~~~~~/licensing~~~~~~
--]
<reference id="[=objectId]" interface="org.apache.camel.Component"
filter="(connection.name=[=objectId])"/>

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://www.apache.org/licenses/LICENSE-2.0
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.

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.entaxy.esb.platform.runtime.core.objects-implementations</groupId>
<artifactId>connection-implementation</artifactId>
<version>1.8.3</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.core.objects-implementations.connection-implementation</groupId>
<artifactId>standard-connections-pack</artifactId>
<packaging>bundle</packaging>
<name>ENTAXY :: PLATFORM :: CORE :: OBJECTS IMPLEMENTATIONS :: CONNECTION :: STANDARD PACK</name>
<description>ENTAXY :: PLATFORM :: CORE :: OBJECTS IMPLEMENTATIONS :: CONNECTION :: STANDARD PACK</description>
<properties>
<bundle.osgi.export.pkg>
ru.entaxy.platform.runtime.connections.*
</bundle.osgi.export.pkg>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-file</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-util</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>base-support</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Entaxy-Factory-Provider>true</Entaxy-Factory-Provider>
<Entaxy-Template-Provider>true</Entaxy-Template-Provider>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,69 @@
/*-
* ~~~~~~licensing~~~~~~
* file-adapter
* ==========
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.platform.runtime.connections.file;
import java.io.File;
import java.util.Map;
import org.apache.camel.component.file.FileComponent;
import org.apache.camel.component.file.GenericFileEndpoint;
import org.apache.camel.util.StringHelper;
import ru.entaxy.platform.base.support.CommonUtils;
public class FileConnectionComponent extends FileComponent {
protected String rootDirectory = "";
@Override
protected GenericFileEndpoint<File> buildFileEndpoint(String uri, String remaining, Map<String, Object> parameters)
throws Exception {
// copied from parent
if (StringHelper.hasStartToken(remaining, "simple")) {
throw new IllegalArgumentException("Invalid directory: " + remaining + ". Dynamic expressions with ${ } placeholders is not allowed."
+ " Use the fileName option to set the dynamic expression.");
}
String current = remaining;
if (CommonUtils.isValid(rootDirectory)) {
current = rootDirectory;
if (CommonUtils.isValid(remaining) && !".".equals(remaining)) {
if (!current.endsWith("/"))
current += "/";
if (remaining.startsWith("/"))
current += remaining.substring(1);
else
current += remaining;
}
}
log.debug("CREATING ENDPOINT FOR [{}]", current);
return super.buildFileEndpoint(uri, current, parameters);
}
public String getRootDirectory() {
return rootDirectory;
}
public void setRootDirectory(String rootDirectory) {
this.rootDirectory = rootDirectory;
}
}

View File

@ -0,0 +1,51 @@
[#ftl]
[#--
~~~~~~licensing~~~~~~
standard-connections-pack
==========
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
http://www.apache.org/licenses/LICENSE-2.0
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.
~~~~~~/licensing~~~~~~
--]
[#if properties??]
[#if properties.createResourceProvider??]
[#if properties.createResourceProvider]
<!-- RESOURCE PROVIDER BEAN -->
<bean id="[=objectId].resourceProvider" class="ru.entaxy.esb.resources.provider.FileResourceProvider">
<property name="protocol" value="[=objectId]" />
<property name="rootDirectory" value="[=properties.rootDirectory]" />
</bean>
<service interface="ru.entaxy.esb.resources.EntaxyResourceProvider" ref="[=objectId].resourceProvider">
<service-properties>
<entry key="connection.name" value="[=objectId]"/>
<entry key="protocol" value="[=objectId]"/>
</service-properties>
</service>
[/#if]
[/#if]
[/#if]
<bean id="[=objectId]" class="ru.entaxy.platform.runtime.connections.file.FileConnectionComponent">
[#if properties??]
[#list properties as key, value]
[#if key?starts_with("camel_")] [#-- we add parent Camel component properties --]
<property name="[=key[6..]]" value="[#if value?is_string][=value][#else][=value?c][/#if]"/>
[/#if]
[/#list]
[/#if]
<property name="rootDirectory" value="[=properties.rootDirectory]" />
</bean>

Some files were not shown because too many files have changed in this diff Show More