ENTAXY-374 release 1.8.2

This commit is contained in:
2022-08-23 13:40:11 +03:00
parent b68642f81c
commit 1061b96c7e
616 changed files with 60896 additions and 3202 deletions

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,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,56 @@
<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>objects-base</artifactId>
<version>1.8.2</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.base.objects-base</groupId>
<artifactId>object-factory</artifactId>
<packaging>bundle</packaging>
<name>ENTAXY :: PLATFORM :: BASE :: OBJECT FACTORING :: OBJECT FACTORY</name>
<description>ENTAXY :: PLATFORM :: BASE :: OBJECT FACTORING :: OBJECT FACTORY</description>
<properties>
<bundle.osgi.export.pkg>
ru.entaxy.platform.base.objects.factory,
ru.entaxy.platform.base.objects.factory.configuration,
ru.entaxy.platform.base.objects.factory.impl,
ru.entaxy.platform.base.objects.factory.tracker
</bundle.osgi.export.pkg>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<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>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>base-support</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.base.connecting.generator
</groupId>
<artifactId>generator-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.base.connecting.generator
</groupId>
<artifactId>generator-factory</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,207 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.gson.JsonObject;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
public interface EntaxyFactory extends EntaxyFactoryElements.EntaxyFactoryExtendedElement {
/*
* public constants, enums etc
*/
public static interface SERVICE {
String PROP_ID = "factory.id";
String PROP_TYPE = "factory.type";
String PROP_ORIGIN_BUNDLE = "factory.origin.bundle";
}
public static interface CONFIGURATION {
String FACTORY_SECTION_NAME = "factory";
String FIELDS_SECTION_NAME = "fields";
String OUTPUTS_SECTION_NAME = "outputs";
public static interface FACTORY {
String ID = "id";
String TYPE = "type";
String DESCRIPTION = "description";
String LABEL = "label";
String CATEGORY = "category";
}
public static interface FIELDS {
public static interface REGULAR_TYPES {
String STRING = "String";
String BOOLEAN = "Boolean";
String LONG = "Long";
String DOUBLE = "Double";
public static Set<String> asSet() {
return new HashSet<>() {{
add(STRING);
add(BOOLEAN);
add(DOUBLE);
add(LONG);
}};
}
}
public static interface ATTRIBUTES {
String FIELD_TYPE = "type";
String DEFAULT_VALUE = "defaultValue";
String REQUIRED = "required";
String IMMUTABLE = "immutable";
String IS_REF = "isRef";
}
String OBJECT_ID = "objectId";
}
public static interface OUTPUTS {
String OUTPUT_TYPE_INIT = "init";
String OUTPUT_TYPE_REF = "ref";
public static interface ATTRIBUTES {
String IS_DEFAULT = "isDefault";
String CONFIG = "config";
String GENERATOR = "generator";
String FIELDS = "fields";
String SCOPES = "scopes";
}
}
}
static public enum SCOPE {
PUBLIC("public"),
PROTECTED("protected"),
PRIVATE("private");
public String label;
private SCOPE(String label) {
this.label = label;
}
public static SCOPE valueOfLabel(String label) {
for (SCOPE e : values()) {
if (e.label.equals(label)) {
return e;
}
}
return null;
}
}
static public SCOPE DEFAULT_SCOPE = SCOPE.PUBLIC;
/*
* inner structure elements
*/
public static interface OutputInfo {
public String getType();
public String getGenerator();
public List<String> getScopes();
public Map<String, Object> getConfig();
public List<FieldInfo> getFields();
public boolean isDefault();
}
public static interface FieldInfo {
public String getName();
public String getType();
public String getDisplayName();
public String getDescription();
public boolean isImmutable();
public boolean isRequired();
public Object getDefaultValue();
public boolean isConditional();
public String getCondition();
public boolean isRef();
public JsonObject getJsonOrigin();
}
public static interface RefFieldInfo extends FieldInfo {
public boolean isBackRef();
public boolean isRefByValueOnly();
public String getRefField();
}
/*
* Factory itself
*/
@Deprecated()
public default String getFactoryId() {
return getId();
};
@Deprecated
public default String getFactoryType() {
return getType();
};
public List<OutputInfo> getOutputs();
public OutputInfo getDefaultOutput();
public OutputInfo getOutputByType(String outputType);
public List<FieldInfo> getFields();
public List<FieldInfo> getFields(String outputType);
public Generated generate(Map<String, Object> parameters) throws EntaxyFactoryException ;
public Generated generate(String outputType, Map<String, Object> parameters) throws EntaxyFactoryException;
public Generated generate(String outputType, String scope, Map<String, Object> parameters) throws EntaxyFactoryException;
}

View File

@ -0,0 +1,49 @@
/*-
* ~~~~~~licensing~~~~~~
* object-factory
* ==========
* Copyright (C) 2020 - 2022 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;
public interface EntaxyFactoryElements {
public interface EntaxyFactoryTypedElement {
String getType();
}
public interface EntaxyFactoryLabeledElement {
String getLabel();
}
public interface EntaxyFactoryCommonElement extends EntaxyFactoryTypedElement {
String getId();
String getDescription();
}
public interface EntaxyFactoryExtendedElement extends EntaxyFactoryCommonElement, EntaxyFactoryLabeledElement {
String getCategory();
}
}

View File

@ -0,0 +1,24 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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;
public class EntaxyFactoryException extends Exception {
}

View File

@ -0,0 +1,33 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.configuration;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
public abstract class AbstractElement<T> {
@SuppressWarnings("unchecked")
public T fromJson(JsonElement jsonElement) {
Gson gson = new Gson();
return (T)gson.fromJson(jsonElement, this.getClass());
};
}

View File

@ -0,0 +1,65 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.configuration;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
public class FactoryElement extends AbstractElement<FactoryElement> {
public static final String ELEMENT_NAME = EntaxyFactory.CONFIGURATION.FACTORY_SECTION_NAME;
protected String id;
protected String type;
protected String description;
protected String label;
protected String category;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
}

View File

@ -0,0 +1,168 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.configuration;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.support.JSONUtils;
public class FieldElement implements EntaxyFactory.FieldInfo {
JsonObject jsonOrigin = null;
String name;
String type;
String displayName;
String description = "";
boolean immutable = false;
boolean required = false;
Object defaultValue = "";
boolean conditional = false;
String condition = null;
boolean isRef = false;
public static FieldElement merge(FieldElement...elements) {
JsonObject result = new JsonObject();
for (int i=0; i<elements.length; i++) {
JsonElement jsonElement = elements[i].jsonOrigin;
if (jsonElement == null)
continue;
if (!jsonElement.isJsonObject())
continue;
JsonObject jsonObject = jsonElement.getAsJsonObject();
JSONUtils.mergeObjects(jsonObject, result);
}
FieldElement fe = (new Gson()).fromJson(result, FieldElement.class);
fe.setJsonOrigin(result.deepCopy());
return fe;
}
/* EntaxyFactory.FieldInfo implementation */
@Override
public String getName() {
return name;
}
@Override
public String getDisplayName() {
return displayName;
}
@Override
public String getDescription() {
return description;
}
@Override
public String getType() {
return type;
}
@Override
public Object getDefaultValue() {
return defaultValue;
}
@Override
public boolean isRequired() {
return required;
}
@Override
public boolean isImmutable() {
return immutable;
}
@Override
public JsonObject getJsonOrigin() {
return jsonOrigin;
}
@Override
public boolean isConditional() {
return conditional;
}
@Override
public String getCondition() {
return condition;
}
@Override
public boolean isRef() {
return isRef;
}
/* other */
public void setName(String name) {
this.name = name;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public void setDescription(String description) {
this.description = description;
}
public void setType(String type) {
this.type = type;
}
public void setDefaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
}
public void setRequired(boolean isRequired) {
this.required = isRequired;
}
public void setImmutable(boolean isImmuable) {
this.immutable = isImmuable;
}
public void setJsonOrigin(JsonObject jsonOrigin) {
this.jsonOrigin = jsonOrigin;
}
public void setConditional(boolean conditional) {
this.conditional = conditional;
}
public void setCondition(String condition) {
this.condition = condition;
}
public void setRef(boolean isRef) {
this.isRef = isRef;
}
}

View File

@ -0,0 +1,89 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.configuration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
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.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.FIELDS;
public class FieldsElement extends AbstractElement<FieldsElement> {
private static final Logger log = LoggerFactory.getLogger(FieldsElement.class);
public static final String ELEMENT_NAME = EntaxyFactory.CONFIGURATION.FIELDS_SECTION_NAME;
protected Map<String, FieldElement> fields = new HashMap<>();
@Override
public FieldsElement fromJson(JsonElement jsonElement) {
Gson gson = new Gson();
if (jsonElement.isJsonObject()) {
for (Entry<String, JsonElement> entry : jsonElement.getAsJsonObject().entrySet()) {
Class<? extends FieldElement> feClass = FieldElement.class;
if (entry.getValue().isJsonObject())
if (entry.getValue().getAsJsonObject().has(FIELDS.ATTRIBUTES.IS_REF)) {
JsonElement val = entry.getValue().getAsJsonObject().get(FIELDS.ATTRIBUTES.IS_REF);
if (val.isJsonPrimitive() && val.getAsJsonPrimitive().isBoolean())
if (val.getAsJsonPrimitive().getAsBoolean()) {
feClass = RefFieldElement.class;
}
}
FieldElement fe = gson.fromJson(entry.getValue(), feClass);
fe.setName(entry.getKey());
fe.setJsonOrigin(entry.getValue().isJsonObject()?entry.getValue().getAsJsonObject():new JsonObject());
addField(fe);
}
}
/*
* this.fields = gson.fromJson( jsonElement,
* TypeToken.getParameterized(ArrayList.class, FieldElement.class).getType() );
*/
// processOutputs();
return this;
}
protected void addField(FieldElement fieldElement) {
this.fields.put(fieldElement.getName(), fieldElement);
}
public Map<String, FieldElement> getFieldsMap(){
return this.fields;
}
public List<FieldElement> getFields() {
return new ArrayList<>(fields.values());
}
}

View File

@ -0,0 +1,231 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.configuration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.factory.GeneratorFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.FieldInfo;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.SCOPE;
public class OutputElement implements EntaxyFactory.OutputInfo {
private static final Logger log = LoggerFactory.getLogger(OutputElement.class);
protected String type;
protected String generator = GeneratorFactory.DEFAULT_GENERATOR;
protected boolean isDefault = false;
protected List<String> scopes = Arrays.asList(new String[] {EntaxyFactory.SCOPE.PUBLIC.name()});
protected Set<SCOPE> supportedScopes = new HashSet<>( Arrays.asList(new SCOPE[] {EntaxyFactory.SCOPE.PUBLIC}) );
protected Map<String, Object> config = new HashMap<>();
protected JsonObject origin;
protected FieldsElement fields = null;
protected Map<String, FieldElement> commonFields = new HashMap<>();
protected Map<String, FieldElement> effectiveFields = new HashMap<>();
protected boolean isEffectiveCalculated = false;
public static OutputElement fromJson(JsonObject jsonObject) {
Gson gson = new Gson();
OutputElement result = gson.fromJson(jsonObject, OutputElement.class);
result.setOrigin(jsonObject);
result.updateFromOrigin();
return result;
}
public static OutputElement fromJson(String type, JsonObject jsonObject) {
OutputElement result = OutputElement.fromJson(jsonObject);
result.setType(type);
return result;
}
public OutputElement() {
super();
}
public void updateFromOrigin() {
if (origin.has(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.FIELDS)) {
JsonElement fieldsElement = origin.get(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.FIELDS);
this.fields = (new FieldsElement()).fromJson(fieldsElement);
}
if (origin.has(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.SCOPES)) {
JsonElement scopesElement = origin.get(EntaxyFactory.CONFIGURATION.OUTPUTS.ATTRIBUTES.SCOPES);
if (scopesElement.isJsonArray()) {
JsonArray ja = scopesElement.getAsJsonArray();
List<String> scopes = new ArrayList<>();
for (int i=0; i<ja.size(); i++)
scopes.add(ja.get(i).getAsString());
setScopes(scopes);
}
}
}
protected void calculateEffective() {
this.effectiveFields.clear();
log.debug("-> " + getType() + " calculateEffective :: " + this.commonFields.size());
Map<String, FieldElement> ownedFields;
if (fields == null) {
// get all common fields
log.debug("-> " + getType() + " taking all common fields");
ownedFields = Collections.emptyMap();
if (commonFields != null)
for (Entry<String, FieldElement> entry: commonFields.entrySet()) {
this.effectiveFields.put(entry.getKey(), entry.getValue());
}
} else {
// use only locally mentioned fields
ownedFields = fields.getFieldsMap();
log.debug("->" + getType() + " ownedFields: " + fields.getFieldsMap().size());
if (commonFields != null)
for (Entry<String, FieldElement> entry: commonFields.entrySet()) {
if (ownedFields.containsKey(entry.getKey())) {
FieldElement fe = FieldElement.merge(entry.getValue(), ownedFields.get(entry.getKey()));
fe.setName(entry.getKey());
this.effectiveFields.put(entry.getKey(), fe);
}
}
}
for (Entry<String, FieldElement> entry: ownedFields.entrySet())
if (!this.effectiveFields.containsKey(entry.getKey()))
this.effectiveFields.put(entry.getKey(), entry.getValue());
this.isEffectiveCalculated = true;
}
@Override
public String getType() {
return type;
}
@Override
public String getGenerator() {
return generator;
}
@Override
public List<String> getScopes() {
return this.supportedScopes.stream().map(s -> s.label).collect(Collectors.toList());
}
@Override
public Map<String, Object> getConfig() {
return config;
}
@Override
public List<FieldInfo> getFields() {
if (!this.isEffectiveCalculated)
calculateEffective();
return this.effectiveFields.values().stream().map(f->(FieldInfo)f).collect(Collectors.toList());
}
@Override
public boolean isDefault() {
return isDefault;
}
public void setType(String type) {
this.type = type;
}
public void setGenerator(String generator) {
this.generator = generator;
}
public void setScopes(String[] scopes) {
log.debug("\n\tsetScopes(String[] scopes)");
if (scopes == null) {
setScopes(Collections.<String>emptyList());
} else {
setScopes(Arrays.asList(scopes));
}
}
public void setScopes(List<String> scopes) {
log.debug("\n\tsetScopes(List<String> scopes)");
this.scopes.clear();
this.supportedScopes.clear();
for (String s: scopes) {
this.scopes.add(s.toLowerCase());
this.supportedScopes.add(SCOPE.valueOfLabel(s));
}
}
public Set<SCOPE> getSupportedScopes() {
return supportedScopes;
}
public boolean isScopeSupported(String scope) {
return isScopeSupported(SCOPE.valueOfLabel(scope));
}
public boolean isScopeSupported(SCOPE scope) {
return supportedScopes.contains(scope);
}
public void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}
public void setConfig(Map<String, Object> config) {
this.config = config;
}
public JsonObject getOrigin() {
return origin;
}
public void setOrigin(JsonObject origin) {
this.origin = origin;
}
public void setCommonFields(Map<String, FieldElement> commonFields) {
this.commonFields = commonFields;
this.isEffectiveCalculated = false;
}
}

View File

@ -0,0 +1,111 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.configuration;
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.Gson;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.support.CommonUtils;
public class OutputsElement extends AbstractElement<OutputsElement> {
public static final String ELEMENT_NAME = EntaxyFactory.CONFIGURATION.OUTPUTS_SECTION_NAME;
public static final String DEFAULT_OUTPUT_TYPE = "init";
// protected List<OutputElement> outputs = new ArrayList<>();
protected Map<String, OutputElement> outputsMap = new HashMap<>();
protected Map<String, FieldElement> commonFields = new HashMap<>();
protected String defaultOutputType = "";
@Override
public OutputsElement fromJson(JsonElement jsonElement) {
Gson gson = new Gson();
/*
* this.outputs = gson.fromJson( jsonElement,
* TypeToken.getParameterized(ArrayList.class, OutputElement.class).getType() );
* processOutputs();
*/
if (jsonElement.isJsonObject()) {
for (Entry<String, JsonElement> entry: jsonElement.getAsJsonObject().entrySet()) {
OutputElement oe = gson.fromJson(entry.getValue(), OutputElement.class);
oe.setType(entry.getKey());
oe.setCommonFields(commonFields);
if (entry.getValue().isJsonObject())
oe.setOrigin(entry.getValue().getAsJsonObject());
oe.updateFromOrigin();
if (oe.isDefault)
this.defaultOutputType = oe.getType();
addOutput(oe);
}
}
if (!CommonUtils.isValid(defaultOutputType))
if (outputsMap.containsKey(DEFAULT_OUTPUT_TYPE)) {
this.defaultOutputType = DEFAULT_OUTPUT_TYPE;
this.outputsMap.get(DEFAULT_OUTPUT_TYPE).setDefault(true);
}
return this;
}
protected void addOutput(OutputElement oe) {
this.outputsMap.put(oe.getType(), oe);
}
public List<OutputElement> getOutputs() {
return new ArrayList<>(outputsMap.values());
}
public String getDefaultOutputType() {
return defaultOutputType;
}
public void setDefaultOutputType(String defaultOutputType) {
this.defaultOutputType = defaultOutputType;
}
public boolean hasOutput(String type) {
return this.outputsMap.containsKey(type);
}
public OutputElement getOutput(String type) {
return this.outputsMap.get(type);
}
public void setCommonFields(Map<String, FieldElement> commonFields) {
this.commonFields = commonFields;
for (OutputElement oe: outputsMap.values())
oe.setCommonFields(commonFields);
}
}

View File

@ -0,0 +1,64 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.configuration;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.FIELDS;
public class RefFieldElement extends FieldElement implements EntaxyFactory.RefFieldInfo {
protected boolean isBackRef = false;
protected boolean isRefByValueOnly = false;
protected String refField = FIELDS.OBJECT_ID;
/* EntaxyFactory.RefFieldInfo */
@Override
public boolean isBackRef() {
return isBackRef;
}
@Override
public boolean isRefByValueOnly() {
return isRefByValueOnly;
}
@Override
public String getRefField() {
return refField;
}
/* others */
public void setBackRef(boolean isBackRef) {
this.isBackRef = isBackRef;
}
public void setRefByValueOnly(boolean isRefByValueOnly) {
this.isRefByValueOnly = isRefByValueOnly;
}
public void setRefField(String refField) {
this.refField = refField;
}
}

View File

@ -0,0 +1,257 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryException;
import ru.entaxy.platform.base.objects.factory.configuration.AbstractElement;
import ru.entaxy.platform.base.objects.factory.configuration.FactoryElement;
import ru.entaxy.platform.base.objects.factory.configuration.FieldsElement;
import ru.entaxy.platform.base.objects.factory.configuration.OutputElement;
import ru.entaxy.platform.base.objects.factory.configuration.OutputsElement;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.JSONUtils;
import ru.entaxy.platform.base.support.osgi.OSGIUtils;
public class DefaultFactory implements EntaxyFactory {
private static final Logger log = LoggerFactory.getLogger(DefaultFactory.class);
protected Map<String, Class<? extends AbstractElement<?>>> elementClasses = new HashMap<>();
protected String factoryId = "";
protected String factoryType = "";
protected String description;
protected String label;
protected String category;
protected FieldsElement fields = null;
protected OutputsElement outputs = new OutputsElement();
protected Map<String, Object> factoryData = new HashMap<>();
protected GenerationHelper helper = null;
public DefaultFactory() {
super();
elementClasses.put(FactoryElement.ELEMENT_NAME, FactoryElement.class);
elementClasses.put(OutputsElement.ELEMENT_NAME, OutputsElement.class);
elementClasses.put(FieldsElement.ELEMENT_NAME, FieldsElement.class);
}
protected GenerationHelper getHelper() {
if (this.helper == null) {
try {
helper = OSGIUtils.services().ofClass(GenerationHelper.class).waitService(5000).get();
} catch (Exception e) {
// TODO Auto-generated catch block
log.error("Error getting GenerationHelper", e);
}
}
return this.helper;
}
public void configure(String configuration) {
log.debug("CONFIGURE WITH: " + configuration);
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
JsonElement je = (new JsonParser()).parse(configuration);
JsonObject root = je.getAsJsonObject();
Set<Entry<String, JsonElement>> elementSet = root.entrySet();
for (Entry<String, JsonElement> entry: elementSet) {
String name = entry.getKey();
Object result = null;
if (elementClasses.containsKey(name)) {
log.debug("FOUND element class for [" + name + "] :: " + elementClasses.get(name));
try {
result = elementClasses.get(name).getConstructor().newInstance().fromJson(entry.getValue());
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
log.error("Error deserializing [" + name + "]", e);
continue;
}
// gson.fromJson(entry.getValue(), elementClasses.get(name));
} else
result = JSONUtils.element2object(entry.getValue());
factoryData.put(name, result);
postprocess(name, result);
}
}
protected void postprocess(String name, Object object) {
if (object instanceof FactoryElement) {
FactoryElement fe = (FactoryElement)object;
log.debug("POSTPROCESS :: FactoryElement");
if (CommonUtils.isValid(fe.getId()))
this.factoryId = fe.getId();
this.factoryType = fe.getType();
this.category = fe.getCategory();
this.label = fe.getLabel();
this.description = fe.getDescription();
} else if (object instanceof OutputsElement) {
log.debug("POSTPROCESS :: OutputsElement");
this.outputs = (OutputsElement)object;
log.debug("POSTPROCESS :: Default output config size -> " +
this.outputs.getOutput(this.outputs.getDefaultOutputType()).getConfig().size()
);
if (this.fields != null) {
this.outputs.setCommonFields(this.fields.getFieldsMap());
log.debug("COMMON FIELDS :: " + this.fields.getFieldsMap().size());
} else {
log.debug("fields :: null");
}
} else if (object instanceof FieldsElement) {
log.debug("POSTPROCESS :: FieldsElement");
this.fields = (FieldsElement)object;
if (this.outputs != null) {
this.outputs.setCommonFields(this.fields.getFieldsMap());
log.debug("COMMON FIELDS :: " + this.fields.getFieldsMap().size());
} else {
log.debug("outputs :: null");
}
}
}
public boolean isValid() {
return CommonUtils.isValid(this.factoryId) && CommonUtils.isValid(this.factoryType);
}
@Override
public String getId() {
return this.factoryId;
}
public void setFactoryId(String factoryId) {
this.factoryId = factoryId;
}
@Override
public String getType() {
return this.factoryType;
}
@Override
public String getDescription() {
return description;
}
@Override
public String getLabel() {
return label;
}
@Override
public String getCategory() {
return category;
}
@Override
public Generated generate(Map<String, Object> parameters) throws EntaxyFactoryException {
return generate(this.outputs.getDefaultOutputType(), parameters);
}
@Override
public Generated generate(String outputType, Map<String, Object> parameters) throws EntaxyFactoryException {
if (!this.outputs.hasOutput(outputType))
throw new EntaxyFactoryException();
return this.generate(outputType, EntaxyFactory.SCOPE.PUBLIC.label, parameters);
}
@Override
public Generated generate(String outputType, String scope, Map<String, Object> parameters) throws EntaxyFactoryException {
log.debug("Generating for: output type [{}], scope [{}]", outputType, scope);
if (!this.outputs.hasOutput(outputType)) {
log.debug("Unknown output: {}", outputType);
throw new EntaxyFactoryException();
}
OutputElement oe = this.outputs.getOutput(outputType);
if (!oe.isScopeSupported(scope)) {
log.error("Scope not supported: {}; supported scopes: [{}]"
, scope
, oe.getSupportedScopes().stream().map(s -> s.label).collect(Collectors.joining(",")));
throw new EntaxyFactoryException();
}
if (this.getHelper() != null)
try {
return this.getHelper().generateForFactory(this, outputType, SCOPE.valueOfLabel(scope), parameters);
} catch (Exception e) {
log.error("Generate failed", e);
// TODO fill the exception
throw new EntaxyFactoryException();
}
return null;
}
@Override
public List<OutputInfo> getOutputs() {
return this.outputs.getOutputs().stream().map(el->(OutputInfo)el).collect(Collectors.toList());
}
@Override
public OutputInfo getOutputByType(String outputType) {
return this.outputs.getOutput(outputType);
}
@Override
public List<FieldInfo> getFields() {
return this.fields.getFields().stream().map(f -> (FieldInfo)f).collect(Collectors.toList());
}
@Override
public List<FieldInfo> getFields(String outputType) {
return this.outputs.getOutput(outputType).getFields();
}
@Override
public OutputInfo getDefaultOutput() {
return (OutputInfo)outputs.getOutput(outputs.getDefaultOutputType());
}
}

View File

@ -0,0 +1,126 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
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.base.generator.template.Template;
import ru.entaxy.base.generator.template.TemplateService;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generator;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.factory.GeneratorFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.OutputInfo;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.SCOPE;
@Component(immediate = true, service = {GenerationHelper.class})
public class GenerationHelper {
private static final Logger log = LoggerFactory.getLogger(GenerationHelper.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY, collectionType = CollectionType.SERVICE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
protected volatile TemplateService templateService;
public Generated generateForFactory(EntaxyFactory factory, String outputType, SCOPE scope, Map<String, Object> parameters) throws Exception {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "]");
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: PARAMETERS \n"
+ parameters.entrySet().stream().map(e -> e.getKey() + ":" + (null==e.getValue()?"null":e.getValue()))
.collect(Collectors.toList())
.stream().collect(Collectors.joining(", "))
);
OutputInfo outputInfo = factory.getOutputByType(outputType);
if (outputInfo == null) {
// @TODO throw Exception
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: output [{}] not found", outputType);
return null;
}
if (!outputInfo.getScopes().contains(scope.label)) {
// @TODO throw Exception
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: scope [{}] not supported", scope.label);
return null;
}
// try to generate via GeneratorFactory
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: TRY via GeneratorFactory");
Generator g = GeneratorFactory.createGenerator(outputInfo.getGenerator(), outputInfo.getConfig());
if (g.isGeneratable(parameters)) {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: generating");
return g.generate(parameters);
} else {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: NOT generatable");
}
// try to generate via TemplateService
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: TRY via TemplateService");
List<String> candidates = new LinkedList<>();
candidates.add(factory.getFactoryId() + "." + outputType + "." + scope.label);
candidates.add(factory.getFactoryId() + "." + outputType);
if (outputInfo.isDefault()) {
candidates.add(factory.getFactoryId() + ".default." + scope.label);
candidates.add(factory.getFactoryId() + ".default");
candidates.add(factory.getFactoryId() + "." + scope.label);
candidates.add(factory.getFactoryId());
}
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: CANDIDATES : ["
+ candidates.stream().collect(Collectors.joining(";"))
+ "]"
);
for (String candidate: candidates) {
Template t = templateService.getTemplateById(candidate);
if (t != null) {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: FOUND TEMPLATE : ["
+ candidate + "]");
Generated result = GeneratorFactory.createGenerator(t).generate(t, parameters);
return result;
} else {
log.debug("GENERATING for factory [" + factory.getFactoryId() + "] :: NOT FOUND TEMPLATE : ["
+ candidate + "]");
}
}
return null;
}
public TemplateService getTemplateService() {
return templateService;
}
public void setTemplateService(TemplateService templateService) {
this.templateService = templateService;
}
}

View File

@ -0,0 +1,84 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.HashMap;
import java.util.Map;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
public class TrackedFactory {
private static final Logger log = LoggerFactory.getLogger(TrackedFactory.class);
public static Map<String, TrackedFactory> trackedFactoriesMap = new HashMap<>();
private String id;
private Bundle bundle;
private String configString;
private ServiceRegistration<EntaxyFactory> serviceRegistration;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Bundle getBundle() {
return bundle;
}
public void setBundle(Bundle bundle) {
this.bundle = bundle;
}
public String getConfigString() {
return configString;
}
public void setConfigString(String configString) {
this.configString = configString;
}
public ServiceRegistration<EntaxyFactory> getServiceRegistration() {
return serviceRegistration;
}
public void setServiceRegistration(ServiceRegistration<EntaxyFactory> serviceRegistration) {
this.serviceRegistration = serviceRegistration;
}
public void unregister() {
if (this.serviceRegistration != null)
try {
this.serviceRegistration.unregister();
} catch (Exception e) {
log.warn("TrackedFactory [" + getId() + "]", e);
}
}
}

View File

@ -0,0 +1,83 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.platform.base.support.osgi.tracker.UniformBundleTrackerCustomizer;
public class TrackedFactoryCustomizer extends UniformBundleTrackerCustomizer<List<TrackedFactory>> {
private static final Logger log = LoggerFactory.getLogger(TrackedFactoryCustomizer.class);
private static final String FACTORY_ROOT_PATH = "/ru/entaxy/factory/";
@Override
protected List<TrackedFactory> createManagedObject(Bundle bundle, BundleEvent event,
Map<String, List<?>> filterResults) {
List<TrackedFactory> result = new ArrayList<>();
Enumeration<URL> entries = bundle.findEntries(FACTORY_ROOT_PATH, "*.json", false);
while (entries.hasMoreElements()) {
URL entry = entries.nextElement();
String urlString = entry.toString();
log.debug("Found path: " + urlString);
if (urlString.endsWith("/"))
continue;
String id = urlString.substring(urlString.lastIndexOf("/") + 1);
id = id.substring(0, id.lastIndexOf("."));
log.debug("Found id: " + id);
try {
String config = new BufferedReader (
new InputStreamReader(
entry.openStream(), StandardCharsets.UTF_8))
.lines()
.collect(Collectors.joining("\n"));
TrackedFactory tf = new TrackedFactory();
tf.setId(id);
tf.setBundle(bundle);
tf.setConfigString(config);
result.add(tf);
} catch (Exception e) {
log.error("Error reading url: " + urlString, e);
}
}
return result;
}
}

View File

@ -0,0 +1,102 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.Dictionary;
import java.util.Hashtable;
import java.util.List;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.base.generator.template.TemplateService;
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
import ru.entaxy.platform.base.objects.factory.impl.DefaultFactory;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.osgi.tracker.BundleTrackerCustomizerListener;
public class TrackedFactoryCustomizerListener implements BundleTrackerCustomizerListener<List<TrackedFactory>> {
private static final Logger log = LoggerFactory.getLogger(TrackedFactoryCustomizerListener.class);
protected BundleContext bundleContext;
public TrackedFactoryCustomizerListener(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
@Override
public void added(List<TrackedFactory> managedObject) {
if (managedObject == null) {
log.debug("managedObject is null");
return;
}
for (TrackedFactory tf: managedObject) {
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());
}
}
}

View File

@ -0,0 +1,69 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.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.Deactivate;
import org.osgi.util.tracker.BundleTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.platform.base.support.osgi.tracker.BundleTrackerUtils;
import ru.entaxy.platform.base.support.osgi.tracker.filter.BundleHeaderFilter;
@Component(service = {TrackerManager.class}, immediate = true)
public class TrackerManager {
private static final Logger log = LoggerFactory.getLogger(TrackerManager.class);
protected BundleContext bundleContext;
protected BundleTracker<List<TrackedFactory>> factoryTracker;
@Activate
public void activate(ComponentContext componentContext) {
this.bundleContext = componentContext.getBundleContext();
log.debug("Activated: " + bundleContext.getBundle().getBundleId());
factoryTracker = BundleTrackerUtils.<List<TrackedFactory>>createBuilder()
.addFilter(
(new BundleHeaderFilter()).header("Entaxy-Factory-Provider")
)
.customizer(
(new TrackedFactoryCustomizer())
.listener(new TrackedFactoryCustomizerListener(bundleContext))
)
.bundleState(Bundle.ACTIVE | Bundle.INSTALLED | Bundle.RESOLVED)
.get();
factoryTracker.open();
log.debug("Factory tracker started");
}
@Deactivate
public void deactivate(ComponentContext componentContext) {
factoryTracker.close();
}
}

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,38 @@
<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>objects-base</artifactId>
<version>1.8.2</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.base.objects-base</groupId>
<artifactId>objects-core</artifactId>
<packaging>bundle</packaging>
<name>ENTAXY :: PLATFORM :: BASE :: OBJECTS BASE :: OBJECTS CORE</name>
<description>ENTAXY :: PLATFORM :: BASE :: OBJECTS BASE :: OBJECTS CORE</description>
<properties>
<bundle.osgi.export.pkg>
ru.entaxy.platform.base.objects,
ru.entaxy.platform.base.objects.service.impl,
ru.entaxy.platform.base.objects.service.tracker,
ru.entaxy.platform.base.objects.shell,
ru.entaxy.platform.base.objects.shell.completers,
ru.entaxy.platform.base.objects.storage.impl
</bundle.osgi.export.pkg>
<bundle.osgi.remove.headers>none</bundle.osgi.remove.headers>
</properties>
<dependencies>
<dependency>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>base-support</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.core</artifactId>
<version>${karaf.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,86 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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;
public interface EntaxyObject {
public interface HEADERS {
String MAIN_OBJECT = "Entaxy-Main-Object";
String GENERATED_OBJECTS = "Entaxy-Generated-Object";
// public static final String HEADER_MAIN_OBJECT_ID = "Entaxy-Main-Object-Id";
// public static final String HEADER_MAIN_OBJECT_TYPE = "Entaxy-Main-Object-Type";
// public static final String HEADER_MAIN_OBJECT_FACTORY_ID = "Entaxy-Main-Object-Factory";
// public static final String HEADER_OBJECT_ID = "Entaxy-Generated-Object";
// public static final String HEADER_OBJECT_TYPE = "Entaxy-Generated-Object-Type";
String GENERATED_OBJECTS_CONFIG = "Entaxy-Generated-Object-Configuration";
}
public interface FIELDS {
public static final String FACTORY_ID = "factoryId";
public static final String SCOPE = "scope";
public static final String OBJECT_ID = "objectId";
public static final String OBJECT_TYPE = "type";
public static final String IS_REF = "isRef";
public static final String IS_BACK_REF = "isBackRef";
public static final String IS_REF_BY_VALUE_ONLY = "isRefByValueOnly";
public static final String REF_FIELD = "refField";
public static final String DEFAULT_VALUE = "defaultValue";
public static final String PROPERTIES = "properties";
public static final String FIELDS_TO_PUBLISH = "##publish";
}
public interface OBJECT_TYPES {
public static final String ENTAXY_RUNTIME_TYPE_PREFIX = "entaxy.runtime.";
public static final String PROFILE = ENTAXY_RUNTIME_TYPE_PREFIX + "profile";
public static final String CONNECTOR = ENTAXY_RUNTIME_TYPE_PREFIX + "connector";
public static final String CONNECTION = ENTAXY_RUNTIME_TYPE_PREFIX + "connection";
public static final String DEFAULT_ROUTE = ENTAXY_RUNTIME_TYPE_PREFIX + "default-route";
public static boolean isRuntimeType(String typeName) {
return (typeName!=null) && typeName.startsWith(ENTAXY_RUNTIME_TYPE_PREFIX);
}
}
public static interface BundleInfo {
public long getBundleId();
}
public String getObjectId();
public String getObjectType();
public default String getObjectFullId() {
return getObjectId() + ":" + getObjectType();
};
public String getFactoryId();
public BundleInfo getBundleInfo();
public String getConfiguration();
}

View File

@ -0,0 +1,28 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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;
import java.util.List;
public interface EntaxyObjectService {
public List<EntaxyObject> getObjects();
}

View File

@ -0,0 +1,29 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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;
import java.util.Map;
public interface EntaxyObjectStorage {
public String[] getObjectTypes();
public Object store(Map<String, Object> data);
}

View File

@ -0,0 +1,26 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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;
public interface EntaxyObjectStorageService {
public EntaxyObjectStorage getObjectStorage(String objectType);
}

View File

@ -0,0 +1,42 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.service.impl;
import org.osgi.framework.BundleContext;
import ru.entaxy.platform.base.objects.EntaxyObject;
public class BundleInfoImpl implements EntaxyObject.BundleInfo {
protected BundleContext bundleContext;
protected long bundleId;
public BundleInfoImpl(BundleContext bundleContext, long trackedBundleId) {
super();
this.bundleContext = bundleContext;
this.bundleId = trackedBundleId;
}
@Override
public long getBundleId() {
return this.bundleId;
}
}

View File

@ -0,0 +1,100 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
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.Deactivate;
import org.osgi.util.tracker.BundleTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.platform.base.objects.EntaxyObject;
import ru.entaxy.platform.base.objects.EntaxyObjectService;
import ru.entaxy.platform.base.objects.service.tracker.TrackedEntaxyObjectCustomizer;
import ru.entaxy.platform.base.objects.service.tracker.TrackedEntaxyObjectCustomizerListener;
import ru.entaxy.platform.base.support.osgi.tracker.BundleTrackerUtils;
import ru.entaxy.platform.base.support.osgi.tracker.filter.BundleHeaderFilter;
@Component(service = {EntaxyObjectService.class}, immediate = true)
public class EntaxyObjectServiceImpl implements EntaxyObjectService {
private static final Logger log = LoggerFactory.getLogger(EntaxyObjectServiceImpl.class);
protected BundleContext bundleContext;
protected BundleTracker<List<TrackedEntaxyObject>> objectTracker;
protected Map<String, TrackedEntaxyObject> trackedObjects = new HashMap<>();
@Activate
public void activate(ComponentContext componentContext) {
this.bundleContext = componentContext.getBundleContext();
openTracker();
}
@Deactivate
public void deactivate(ComponentContext componentContext) {
this.objectTracker.close();
}
@Override
public List<EntaxyObject> getObjects() {
return trackedObjects.values().stream().collect(Collectors.toList());
}
protected void openTracker() {
objectTracker = BundleTrackerUtils.<List<TrackedEntaxyObject>>createBuilder()
.addFilter(
(new BundleHeaderFilter()).header(EntaxyObject.HEADERS.GENERATED_OBJECTS)
)
.customizer(
(new TrackedEntaxyObjectCustomizer(this))
.listener(new TrackedEntaxyObjectCustomizerListener(this))
)
.bundleState(Bundle.ACTIVE | Bundle.INSTALLED | Bundle.RESOLVED)
.get();
objectTracker.open();
}
public BundleContext getBundleContext() {
return bundleContext;
}
public void addObjects(List<TrackedEntaxyObject> objects) {
for (TrackedEntaxyObject object: objects)
this.trackedObjects.put(object.getObjectId() + ":" + object.getObjectType(), object);
}
public void removeObjects(List<TrackedEntaxyObject> objects) {
for (TrackedEntaxyObject object: objects)
this.trackedObjects.remove(object.getObjectId() + ":" + object.getObjectType());
}
}

View File

@ -0,0 +1,99 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.service.impl;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import com.google.gson.JsonObject;
import ru.entaxy.platform.base.objects.EntaxyObject;
import ru.entaxy.platform.base.support.JSONUtils;
public class TrackedEntaxyObject implements EntaxyObject {
static public TrackedEntaxyObject create(BundleContext bundleContext, String objectId, String objectType) {
return new TrackedEntaxyObject(bundleContext, objectId, objectType);
}
protected BundleContext bundleContext;
protected String objectId;
protected String objectType;
protected String factoryId = "UNKNOWN";
protected JsonObject configuration;
protected BundleInfoImpl bundleInfoImpl;
protected TrackedEntaxyObject(BundleContext bundleContext, String objectId, String objectType) {
super();
this.bundleContext = bundleContext;
this.objectId = objectId;
this.objectType = objectType;
}
@Override
public String getObjectId() {
return this.objectId;
}
@Override
public String getObjectType() {
return this.objectType;
}
@Override
public String getFactoryId() {
return this.factoryId;
}
@Override
public BundleInfo getBundleInfo() {
return this.bundleInfoImpl;
}
@Override
public String getConfiguration() {
return (this.configuration == null?"{}":this.configuration.toString());
}
public TrackedEntaxyObject bundle(Bundle bundleValue) {
this.bundleInfoImpl = new BundleInfoImpl(bundleContext, bundleValue.getBundleId());
return this;
};
public TrackedEntaxyObject configuration(String configurationValue) {
try {
this.configuration = JSONUtils.getJsonRootObject(configurationValue);
if (this.configuration.has(EntaxyObject.FIELDS.FACTORY_ID))
this.factoryId = this.configuration.get(EntaxyObject.FIELDS.FACTORY_ID).getAsString();
} catch (Exception e) {
}
if (this.configuration == null)
this.configuration = new JsonObject();
return this;
};
}

View File

@ -0,0 +1,76 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.service.tracker;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import ru.entaxy.platform.base.objects.EntaxyObject;
import ru.entaxy.platform.base.objects.service.impl.EntaxyObjectServiceImpl;
import ru.entaxy.platform.base.objects.service.impl.TrackedEntaxyObject;
import ru.entaxy.platform.base.support.CommonUtils;
import ru.entaxy.platform.base.support.osgi.tracker.UniformBundleTrackerCustomizer;
public class TrackedEntaxyObjectCustomizer extends UniformBundleTrackerCustomizer<List<TrackedEntaxyObject>> {
protected EntaxyObjectServiceImpl objectServiceImpl;
public TrackedEntaxyObjectCustomizer(EntaxyObjectServiceImpl objectServiceImpl) {
super();
this.objectServiceImpl = objectServiceImpl;
}
@Override
protected List<TrackedEntaxyObject> createManagedObject(Bundle bundle, BundleEvent event,
Map<String, List<?>> filterResults) {
List<TrackedEntaxyObject> result = new ArrayList<>();
String objectsHeader = bundle.getHeaders().get(EntaxyObject.HEADERS.GENERATED_OBJECTS);
String configHeader = bundle.getHeaders().get(EntaxyObject.HEADERS.GENERATED_OBJECTS_CONFIG);
String[] objects = objectsHeader.split(",");
String[] configs = configHeader.split(",");
for (int i=0; i<objects.length; i++) {
String[] objectData = objects[i].split(":");
String configuration = configs[i];
if (CommonUtils.isValid(configuration)) {
byte[] bytes = Base64.getDecoder().decode(configuration);
configuration = new String(bytes);
} else {
configuration = "{}";
}
TrackedEntaxyObject obj = TrackedEntaxyObject.create(
objectServiceImpl.getBundleContext(), objectData[0], objectData[1]
).bundle(bundle).configuration(configuration);
result.add(obj);
}
return result;
}
}

View File

@ -0,0 +1,54 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.service.tracker;
import java.util.List;
import ru.entaxy.platform.base.objects.service.impl.EntaxyObjectServiceImpl;
import ru.entaxy.platform.base.objects.service.impl.TrackedEntaxyObject;
import ru.entaxy.platform.base.support.osgi.tracker.BundleTrackerCustomizerListener;
public class TrackedEntaxyObjectCustomizerListener implements BundleTrackerCustomizerListener<List<TrackedEntaxyObject>> {
protected EntaxyObjectServiceImpl objectServiceImpl;
public TrackedEntaxyObjectCustomizerListener(EntaxyObjectServiceImpl objectServiceImpl) {
super();
this.objectServiceImpl = objectServiceImpl;
}
@Override
public void added(List<TrackedEntaxyObject> managedObject) {
this.objectServiceImpl.addObjects(managedObject);
}
@Override
public void modified(List<TrackedEntaxyObject> managedObject) {
// TODO Auto-generated method stub
}
@Override
public void removed(List<TrackedEntaxyObject> managedObject) {
this.objectServiceImpl.removeObjects(managedObject);
}
}

View File

@ -0,0 +1,33 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.shell;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import ru.entaxy.platform.base.objects.EntaxyObjectService;
public class EntaxyObjectServiceSupport {
public static final String OBJECTS_SCOPE = "objects";
@Reference
EntaxyObjectService objectService;
}

View File

@ -0,0 +1,57 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.shell;
import org.apache.karaf.shell.api.action.Action;
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;
import ru.entaxy.platform.base.objects.EntaxyObject;
@Service
@Command(name = "object-list", scope = EntaxyObjectServiceSupport.OBJECTS_SCOPE)
public class ListObjects extends EntaxyObjectServiceSupport implements Action {
@Override
public Object execute() throws Exception {
ShellTable shellTable = new ShellTable();
shellTable.column("Id");
shellTable.column("Type");
shellTable.column("Full Id");
shellTable.column("Factory Id");
shellTable.column("Bundle Id");
for (EntaxyObject object: objectService.getObjects())
shellTable.addRow().addContent(
object.getObjectId(),
object.getObjectType(),
object.getObjectFullId(),
object.getFactoryId(),
object.getBundleInfo().getBundleId()
);
shellTable.print(System.out);
return null;
}
}

View File

@ -0,0 +1,56 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.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.Argument;
import org.apache.karaf.shell.api.action.Completion;
import ru.entaxy.platform.base.objects.EntaxyObject;
import ru.entaxy.platform.base.objects.shell.completers.ObjectCompleter;
public abstract class ObjectAwareCommand extends EntaxyObjectServiceSupport implements Action {
@Argument (index = 0, name = "objectFullId", required = true)
@Completion(caseSensitive = false, value = ObjectCompleter.class)
String objectFullId;
EntaxyObject entaxyObject;
@Override
public Object execute() throws Exception {
List<EntaxyObject> candidates = objectService.getObjects()
.stream().filter(obj->obj.getObjectFullId().equals(objectFullId))
.collect(Collectors.toList());
if (candidates.size()>0) {
entaxyObject = candidates.get(0);
return doExecute();
} else {
throw new IllegalArgumentException("Object not found by full Id: [" + objectFullId + "]");
}
}
public abstract Object doExecute() throws Exception;
}

View File

@ -0,0 +1,35 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.shell;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.lifecycle.Service;
@Service
@Command(name = "object-config", scope = EntaxyObjectServiceSupport.OBJECTS_SCOPE)
public class ObjectConfiguration extends ObjectAwareCommand {
@Override
public Object doExecute() throws Exception {
System.out.println(entaxyObject.getConfiguration());
return null;
}
}

View File

@ -0,0 +1,51 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.shell.completers;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.apache.karaf.shell.api.console.CommandLine;
import org.apache.karaf.shell.api.console.Completer;
import org.apache.karaf.shell.api.console.Session;
import ru.entaxy.platform.base.objects.EntaxyObjectService;
@Service
public class ObjectCompleter implements Completer {
@Reference
EntaxyObjectService objectService;
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
candidates.addAll(
objectService.getObjects().stream()
.map(obj->obj.getObjectFullId())
.collect(Collectors.toList())
);
return 0;
}
}

View File

@ -0,0 +1,63 @@
/*-
* ~~~~~~licensing~~~~~~
* test-producers
* ==========
* Copyright (C) 2020 - 2022 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.storage.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.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import ru.entaxy.platform.base.objects.EntaxyObjectStorage;
import ru.entaxy.platform.base.objects.EntaxyObjectStorageService;
@Component(service = EntaxyObjectStorageService.class, immediate = true)
public class EntaxyObjectStorageServiceImpl implements EntaxyObjectStorageService {
protected Map<String, EntaxyObjectStorage> objectStorages = new HashMap<>();
@Override
public EntaxyObjectStorage getObjectStorage(String objectType) {
return this.objectStorages.get(objectType);
}
@Reference(bind = "addObjectStorage", unbind = "removeObjectStorage", cardinality = ReferenceCardinality.MULTIPLE
, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY, collectionType = CollectionType.SERVICE)
public void addObjectStorage(EntaxyObjectStorage objectStorage) {
String[] types = objectStorage.getObjectTypes();
if (types == null)
return;
for (int i=0; i<types.length; i++)
this.objectStorages.put(types[i], objectStorage);
}
public void removeObjectStorage(EntaxyObjectStorage objectStorage) {
String[] types = objectStorage.getObjectTypes();
if (types == null)
return;
for (int i=0; i<types.length; i++)
this.objectStorages.remove(types[i]);
}
}

View File

@ -0,0 +1,31 @@
<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.2</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>objects-base</artifactId>
<packaging>pom</packaging>
<name>ENTAXY :: PLATFORM :: BASE :: OBJECT-FACTORING</name>
<description>ENTAXY :: PLATFORM :: BASE :: OBJECT-FACTORING</description>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<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>
</dependencies>
<modules>
<module>objects-core</module>
<module>object-factory</module>
</modules>
</project>