ENTAXY-480 release version 1.8.3
This commit is contained in:
@ -0,0 +1,28 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-api
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.api;
|
||||
|
||||
public interface EntaxyFactoryDataProcessor {
|
||||
|
||||
default Object processDefaultValue(Object currentValue) {
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
{
|
||||
"general": {
|
||||
"*":{"printOutput":false, "maxCount": 50},
|
||||
"add-config":{},
|
||||
"process-resources":{},
|
||||
"validate":{},
|
||||
"generate":{},
|
||||
"build":{"artifact.version.policy":"dated-embedded"},
|
||||
"install":{"installLocal":false, "update":""},
|
||||
"deploy":{"deployLocal":false},
|
||||
"store": {}
|
||||
},
|
||||
"local": {
|
||||
"install":{"installLocal":true},
|
||||
"deploy":{"deployLocal":true}
|
||||
},
|
||||
"debug": {
|
||||
"*":{"printOutput":true}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.builder;
|
||||
|
||||
public interface BuiltObject {
|
||||
|
||||
Object getObject();
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.builder;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.collections4.list.AbstractLinkedList;
|
||||
|
||||
public class BuiltObjectList extends AbstractLinkedList<BuiltObject> {
|
||||
|
||||
public BuiltObjectList() {
|
||||
super(Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.builder;
|
||||
|
||||
public class DefaultBuiltObject implements BuiltObject {
|
||||
|
||||
protected Object object;
|
||||
|
||||
public DefaultBuiltObject(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.builder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
|
||||
public interface ObjectBuilder {
|
||||
|
||||
boolean isBuildable(Generated generated);
|
||||
BuiltObject build(Generated generated, Map<String, Object> instructions) throws Exception;
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.deployer;
|
||||
|
||||
public class DefaultDeployedObject implements DeployedObject {
|
||||
|
||||
protected Object object;
|
||||
|
||||
public DefaultDeployedObject(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.deployer;
|
||||
|
||||
public interface DeployedObject {
|
||||
|
||||
Object getObject();
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.deployer;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.collections4.list.AbstractLinkedList;
|
||||
|
||||
public class DeployedObjectList extends AbstractLinkedList<DeployedObject> {
|
||||
|
||||
public DeployedObjectList() {
|
||||
super(Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.deployer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import ru.entaxy.platform.core.producer.executor.builder.BuiltObject;
|
||||
|
||||
public interface ObjectDeployer {
|
||||
|
||||
boolean isDeployable(BuiltObject object);
|
||||
DeployedObject deploy(BuiltObject object, Map<String, Object> instructions) throws Exception;
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.installer;
|
||||
|
||||
public class DefaultInstalledObject implements InstalledObject {
|
||||
|
||||
protected Object object;
|
||||
|
||||
public DefaultInstalledObject(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.installer;
|
||||
|
||||
public interface InstalledObject {
|
||||
|
||||
Object getObject();
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.installer;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.collections4.list.AbstractLinkedList;
|
||||
|
||||
public class InstalledObjectList extends AbstractLinkedList<InstalledObject> {
|
||||
|
||||
public InstalledObjectList() {
|
||||
super(Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.installer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import ru.entaxy.platform.core.producer.executor.deployer.DeployedObject;
|
||||
|
||||
public interface ObjectInstaller {
|
||||
|
||||
boolean isInstallable(DeployedObject object);
|
||||
InstalledObject install(DeployedObject object, Map<String, Object> instructions) throws Exception;
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.support;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyProducerService.INSTRUCTIONS;
|
||||
|
||||
public class AbstractPrintOutputSupport implements PrintOutputSupport{
|
||||
|
||||
protected boolean isPrintOutput = false;
|
||||
|
||||
@Override
|
||||
public boolean isPrintOutput() {
|
||||
return isPrintOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrintOutput(boolean isPrintOutput) {
|
||||
this.isPrintOutput = isPrintOutput;
|
||||
}
|
||||
|
||||
protected void setPrintOutput(Map<String, Object> parameters) {
|
||||
if (parameters == null)
|
||||
return;
|
||||
if (parameters.containsKey(INSTRUCTIONS.PRINT_OUTPUT)) {
|
||||
Object val = parameters.get(INSTRUCTIONS.PRINT_OUTPUT);
|
||||
if (val == null)
|
||||
return;
|
||||
if (val instanceof Boolean)
|
||||
this.isPrintOutput = (Boolean)val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,307 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.support;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.osgi.framework.Constants;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject.FIELDS;
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject.HEADERS;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.core.artifact.Artifact;
|
||||
import ru.entaxy.platform.core.artifact.ArtifactManifest;
|
||||
import ru.entaxy.platform.core.artifact.Artifacts;
|
||||
import ru.entaxy.platform.core.artifact.Blueprint;
|
||||
import ru.entaxy.platform.core.artifact.DeployedArtifact;
|
||||
import ru.entaxy.platform.core.artifact.Manifested;
|
||||
import ru.entaxy.platform.core.artifact.capabilities.ManifestCapabilityHelper;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.ClusterInstaller;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.InstallationResult;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.Installer;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.LocalInstaller;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.BlueprintInstaller;
|
||||
import ru.entaxy.platform.core.artifact.service.ArtifactService;
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyProducerService;
|
||||
import ru.entaxy.platform.core.producer.executor.CommandInstructions;
|
||||
import ru.entaxy.platform.core.producer.executor.builder.BuiltObject;
|
||||
import ru.entaxy.platform.core.producer.executor.builder.DefaultBuiltObject;
|
||||
import ru.entaxy.platform.core.producer.executor.builder.ObjectBuilder;
|
||||
import ru.entaxy.platform.core.producer.executor.commands.Deploy;
|
||||
import ru.entaxy.platform.core.producer.executor.commands.Install;
|
||||
import ru.entaxy.platform.core.producer.executor.deployer.DefaultDeployedObject;
|
||||
import ru.entaxy.platform.core.producer.executor.deployer.DeployedObject;
|
||||
import ru.entaxy.platform.core.producer.executor.deployer.ObjectDeployer;
|
||||
import ru.entaxy.platform.core.producer.executor.generationmodel.GeneratedHeaders;
|
||||
import ru.entaxy.platform.core.producer.executor.installer.DefaultInstalledObject;
|
||||
import ru.entaxy.platform.core.producer.executor.installer.InstalledObject;
|
||||
import ru.entaxy.platform.core.producer.executor.installer.ObjectInstaller;
|
||||
|
||||
@Component (service = { ObjectBuilder.class, ObjectDeployer.class, ObjectInstaller.class}, immediate = true)
|
||||
public class ArtifactSupport implements ObjectBuilder, ObjectDeployer, ObjectInstaller {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ArtifactSupport.class);
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY)
|
||||
ArtifactService artifactService;
|
||||
|
||||
/*
|
||||
* ObjectBuilder
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean isBuildable(Generated generated) {
|
||||
Artifact artifact = Artifacts.fromGenerated(generated);
|
||||
if ((artifact == null) || Artifact.ARTIFACT_CATEGORY_UNKNOWN.equals(artifact.getCategory())
|
||||
|| !CommonUtils.isValid(artifact.getCategory())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltObject build(Generated generated, Map<String, Object> instructions) throws Exception {
|
||||
|
||||
LocalPrintOutput printer = new LocalPrintOutput(instructions);
|
||||
|
||||
Artifact artifact = Artifacts.fromGenerated(generated);
|
||||
if ((artifact == null) || Artifact.ARTIFACT_CATEGORY_UNKNOWN.equals(artifact.getCategory())
|
||||
|| !CommonUtils.isValid(artifact.getCategory())) {
|
||||
log.info("Artifact is not buildable");
|
||||
return null;
|
||||
}
|
||||
log.info("Built artifact of category [{}]", artifact.getCategory());
|
||||
Map<String, String> headers = GeneratedHeaders.getHeaders(
|
||||
//generated.getProperties()
|
||||
EntaxyObjectPropertiesHelper.getMainObjectProperties(generated.getProperties())
|
||||
).getAsStringMap();
|
||||
|
||||
String mainObjectValue = headers.get(HEADERS.MAIN_OBJECT);
|
||||
if (!CommonUtils.isValid(mainObjectValue))
|
||||
throw new Exception("Main object not found");
|
||||
String[] mainObjectData = mainObjectValue.split(":");
|
||||
if (mainObjectData.length<2)
|
||||
throw new Exception("Main object not complete: [" + mainObjectValue + "]");
|
||||
|
||||
String versionPolicy = generated.getProperties().getOrDefault(
|
||||
EntaxyProducerService.INSTRUCTIONS.ARTIFACT.VERSION_POLICY,
|
||||
instructions.getOrDefault(
|
||||
EntaxyProducerService.INSTRUCTIONS.ARTIFACT.VERSION_POLICY
|
||||
, ""))
|
||||
.toString();
|
||||
String timestamp = generated.getProperties().getOrDefault(
|
||||
EntaxyProducerService.INSTRUCTIONS.ARTIFACT.TIMESTAMP,
|
||||
instructions.getOrDefault(
|
||||
EntaxyProducerService.INSTRUCTIONS.ARTIFACT.TIMESTAMP
|
||||
, ""))
|
||||
.toString();
|
||||
artifact.getCoordinates()
|
||||
.groupId(mainObjectData[1])
|
||||
.artifactId(mainObjectData[0])
|
||||
.version("1")
|
||||
.versionPolicy(versionPolicy)
|
||||
.timestamp(timestamp);
|
||||
|
||||
if (artifact instanceof Manifested) {
|
||||
ArtifactManifest manifest = ((Manifested)artifact).getManifest();
|
||||
manifest.getCustomAttributes().putAll(headers);
|
||||
|
||||
// Generate provided capabilities for every included object
|
||||
ManifestCapabilityHelper helper = new ManifestCapabilityHelper(manifest);
|
||||
|
||||
String objectsValue = headers.getOrDefault(HEADERS.GENERATED_OBJECTS, "");
|
||||
if (CommonUtils.isValid(objectsValue)) {
|
||||
String[] objects = objectsValue.split(",");
|
||||
|
||||
for (int i=0; i<objects.length; i++) {
|
||||
String[] objectData = objects[i].split(":");
|
||||
if (objectData.length<2)
|
||||
continue;
|
||||
String objectId = objectData[0];
|
||||
String objectType = objectData[1];
|
||||
if (!CommonUtils.isValid(objectId) || !CommonUtils.isValid(objectType))
|
||||
continue;
|
||||
objectId = objectId.trim();
|
||||
objectType = objectType.trim();
|
||||
Map<String, Object> attributes = null;
|
||||
Map<String, Object> objectProperties = EntaxyObjectPropertiesHelper
|
||||
.getPropertiesFor(objectId, objectType, generated.getProperties());
|
||||
if (objectProperties.containsKey(FIELDS.FIELDS_TO_PUBLISH)) {
|
||||
Object map = objectProperties.get(FIELDS.FIELDS_TO_PUBLISH);
|
||||
if (map != null) {
|
||||
attributes = (Map<String, Object>)((Map<String, Object>)map).get(objectId);
|
||||
}
|
||||
}
|
||||
helper.provideCapability(objectType).attributes(attributes);
|
||||
}
|
||||
|
||||
helper.save();
|
||||
|
||||
}
|
||||
}
|
||||
artifact.getProperties().putAll(generated.getProperties());
|
||||
// TODO get value from manifest
|
||||
// ArtifactManifest must be improved to provide read access to all attributes
|
||||
if (!artifact.getProperties().containsKey(Constants.BUNDLE_SYMBOLICNAME)) {
|
||||
artifact.getProperties().put(Constants.BUNDLE_SYMBOLICNAME
|
||||
, artifact.getCoordinates().getGroupId()
|
||||
+ "." + artifact.getCoordinates().getArtifactId());
|
||||
}
|
||||
printer.printOutput("\n\t == " + artifact.getCoordinates().toString() + " ==\n");
|
||||
printer.printOutput(new String(artifact.asByteArray()));
|
||||
printer.printOutput("\n\t == \n");
|
||||
return new DefaultBuiltObject(artifact);
|
||||
}
|
||||
|
||||
/*
|
||||
* ObjectDeployer
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean isDeployable(BuiltObject object) {
|
||||
return object.getObject() instanceof Artifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeployedObject deploy(BuiltObject object, Map<String, Object> instructions) throws Exception {
|
||||
|
||||
if (!(object.getObject() instanceof Artifact)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LocalPrintOutput printer = new LocalPrintOutput(instructions);
|
||||
|
||||
boolean deployLocal = false;
|
||||
|
||||
Object deployLocalValue = instructions.get(Deploy.DEPLOY_LOCAL_INSTRUCTION);
|
||||
if (deployLocalValue != null)
|
||||
if (deployLocalValue instanceof Boolean)
|
||||
deployLocal = (Boolean)deployLocalValue;
|
||||
|
||||
Artifact artifact = (Artifact)object.getObject();
|
||||
|
||||
DeployedArtifact da = deployLocal
|
||||
?artifactService.deployLocal(artifact)
|
||||
:artifactService.deployShared(artifact);
|
||||
|
||||
printer.printOutput("DEPLOYED: ["
|
||||
+ da.getLocation()
|
||||
+ "]");
|
||||
|
||||
return new DefaultDeployedObject(da);
|
||||
}
|
||||
|
||||
/*
|
||||
* ObjectInstaller
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean isInstallable(DeployedObject object) {
|
||||
return object.getObject() instanceof DeployedArtifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstalledObject install(DeployedObject object, Map<String, Object> instructions) throws Exception {
|
||||
|
||||
if (!isInstallable(object))
|
||||
return null;
|
||||
|
||||
LocalPrintOutput printer = new LocalPrintOutput(instructions);
|
||||
|
||||
CommandInstructions commandInstructions = new CommandInstructions(instructions);
|
||||
|
||||
boolean installLocal =
|
||||
commandInstructions.has(Install.INSTALL_LOCAL_INSTRUCTION)
|
||||
?commandInstructions.getBoolean(Install.INSTALL_LOCAL_INSTRUCTION)
|
||||
:false;
|
||||
|
||||
boolean installOnlyIfMissing =
|
||||
commandInstructions.has(Install.INSTALL_ONLY_IF_MISSING_INSTRUCTION)
|
||||
?commandInstructions.getBoolean(Install.INSTALL_ONLY_IF_MISSING_INSTRUCTION)
|
||||
:false;
|
||||
|
||||
String update =
|
||||
commandInstructions.has(Install.UPDATE_INSTRUCTION)
|
||||
?commandInstructions.getString(Install.UPDATE_INSTRUCTION)
|
||||
:null;
|
||||
|
||||
DeployedArtifact da = (DeployedArtifact)object.getObject();
|
||||
|
||||
InstallationResult result = null;
|
||||
|
||||
Installer<?> installer = null;
|
||||
|
||||
String artifactUpdate = update;
|
||||
|
||||
printer.printOutput("-> Installing artifact: [" + da.getArtifact().getCoordinates().toString() + "]");
|
||||
if (installLocal) {
|
||||
LocalInstaller localInstaller = artifactService.installers().local()
|
||||
.artifact(da);
|
||||
installer = localInstaller;
|
||||
printer.printOutput("-> Installing locally");
|
||||
} else {
|
||||
ClusterInstaller clusterInstaller = artifactService.installers().cluster()
|
||||
.artifact(da);
|
||||
installer = clusterInstaller;
|
||||
printer.printOutput("-> Installing clustered");
|
||||
}
|
||||
|
||||
// TODO add support for other types when they appear
|
||||
if (da.getArtifact().getCategory().equals(Blueprint.ARTIFACT_CATEGORY_BLUEPRINT)) {
|
||||
// we're installing blueprint
|
||||
printer.printOutput("-> Installing: " + da.getArtifact().getCategory());
|
||||
BlueprintInstaller blueprintInstaller = installer.typed(BlueprintInstaller.class);
|
||||
if (installOnlyIfMissing)
|
||||
blueprintInstaller.installOnlyIfMissing();
|
||||
if (artifactUpdate != null) {
|
||||
if (!CommonUtils.isValid(artifactUpdate)) {
|
||||
artifactUpdate = da
|
||||
.getArtifact().getProperties()
|
||||
.getOrDefault(Constants.BUNDLE_SYMBOLICNAME, "")
|
||||
.toString();
|
||||
}
|
||||
blueprintInstaller.update(artifactUpdate);
|
||||
}
|
||||
result = blueprintInstaller.start().install();
|
||||
} else {
|
||||
printer.printOutput("-> Unknown category: " + da.getArtifact().getCategory());
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
for (String key: da.getArtifact().getProperties().keySet())
|
||||
result.getProperties().putIfAbsent(key, da.getArtifact().getProperties().get(key));
|
||||
// TODO imrove Coordinates: add "asMap" method
|
||||
result.getProperties().put("artifact.artifactId", da.getArtifact().getCoordinates().getArtifactId());
|
||||
result.getProperties().put("artifact.groupId", da.getArtifact().getCoordinates().getGroupId());
|
||||
result.getProperties().put("artifact.version", da.getArtifact().getCoordinates().getVersion());
|
||||
result.getProperties().put("artifact.type", da.getArtifact().getCoordinates().getType());
|
||||
result.getProperties().put("artifact.classifier", da.getArtifact().getCoordinates().getClassifier());
|
||||
}
|
||||
|
||||
|
||||
return new DefaultInstalledObject(result);
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.support;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject.FIELDS;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
|
||||
public class EntaxyObjectPropertiesHelper {
|
||||
|
||||
public static final String PROP_IS_MERGED = "###MERGED";
|
||||
public static final String PROP_MAIN_OBJECT_DATA = "###MAIN";
|
||||
|
||||
public static boolean isMerged(Map<String, Object> properties) {
|
||||
return (properties!=null) && (properties.containsKey(PROP_IS_MERGED));
|
||||
}
|
||||
|
||||
public static Map<String, Object> merge(Map<String, Object> source, Map<String, Object> target){
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(PROP_IS_MERGED, true);
|
||||
result.putAll(extractObjects(target));
|
||||
result.putAll(extractObjects(source));
|
||||
result.put(PROP_MAIN_OBJECT_DATA, getMainObjectProperties(target));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<String, Object> getPropertiesFor(String objectId, String objectType, Map<String, Object> data){
|
||||
Map<String, Map<String, Object>> extracted = extractObjects(data);
|
||||
return extracted.getOrDefault(createKey(objectId, objectType), new HashMap<>());
|
||||
}
|
||||
|
||||
public static Map<String, Object> getMainObjectProperties(Map<String, Object> data){
|
||||
Map<String, Map<String, Object>> extracted = extractObjects(data);
|
||||
if (extracted.containsKey(PROP_MAIN_OBJECT_DATA))
|
||||
return (Map<String, Object>)extracted.get(PROP_MAIN_OBJECT_DATA);
|
||||
if (extracted.size() >= 1)
|
||||
return (Map<String, Object>)extracted.values().iterator().next();
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
private static String createKey(String objectId, String objectType) {
|
||||
return CommonUtils.getValid(objectId, "") + ":" + CommonUtils.getValid(objectType, "");
|
||||
}
|
||||
|
||||
private static Map<String, Map<String, Object>> extractObjects(Map<String, Object> source){
|
||||
Map<String, Map<String, Object>> result = new HashMap<>();
|
||||
if (isMerged(source)) {
|
||||
for (Entry<String, Object> entry: source.entrySet()) {
|
||||
if (PROP_IS_MERGED.equals(entry.getKey()))
|
||||
continue;
|
||||
if (entry.getValue() instanceof Map) {
|
||||
result.put(entry.getKey(), (Map<String, Object>)entry.getValue());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String objectId = source.getOrDefault(FIELDS.OBJECT_ID, "").toString();
|
||||
String objectType = source.getOrDefault(FIELDS.OBJECT_TYPE, "").toString();
|
||||
if (CommonUtils.isValid(objectId) && CommonUtils.isValid(objectType)) {
|
||||
String key = createKey(objectId, objectType);
|
||||
result.put(key, source);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.support;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class LocalPrintOutput extends AbstractPrintOutputSupport {
|
||||
|
||||
public LocalPrintOutput(Map<String, Object> instructions) {
|
||||
setPrintOutput(instructions);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.support;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
import ru.entaxy.platform.core.producer.executor.builder.BuiltObject;
|
||||
import ru.entaxy.platform.core.producer.executor.builder.ObjectBuilder;
|
||||
import ru.entaxy.platform.core.producer.executor.deployer.DeployedObject;
|
||||
import ru.entaxy.platform.core.producer.executor.deployer.ObjectDeployer;
|
||||
import ru.entaxy.platform.core.producer.executor.installer.ObjectInstaller;
|
||||
|
||||
@Component (service = ObjectSupportRegistry.class, immediate = true)
|
||||
public class ObjectSupportRegistry {
|
||||
|
||||
private static ObjectSupportRegistry INSTANCE = null;
|
||||
|
||||
public static ObjectSupportRegistry getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
|
||||
volatile List<ObjectBuilder> objectBuilders;
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
|
||||
volatile List<ObjectDeployer> objectDeployers;
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
|
||||
volatile List<ObjectInstaller> objectInstallers;
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
public ObjectBuilder findBuilder(Generated generated) {
|
||||
synchronized (this.objectBuilders) {
|
||||
for (ObjectBuilder ob: this.objectBuilders)
|
||||
if (ob.isBuildable(generated))
|
||||
return ob;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ObjectDeployer findDeployer(BuiltObject object) {
|
||||
synchronized (this.objectDeployers) {
|
||||
for (ObjectDeployer od: this.objectDeployers)
|
||||
if (od.isDeployable(object))
|
||||
return od;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ObjectInstaller findInstaller(DeployedObject object) {
|
||||
synchronized (this.objectInstallers) {
|
||||
for (ObjectInstaller oi: this.objectInstallers)
|
||||
if (oi.isInstallable(object))
|
||||
return oi;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.executor.support;
|
||||
|
||||
public interface PrintOutputSupport {
|
||||
|
||||
void setPrintOutput(boolean printOutput);
|
||||
|
||||
boolean isPrintOutput();
|
||||
|
||||
default void printOutput(String message) {
|
||||
if (isPrintOutput())
|
||||
// OUTPUT TO CONSOLE
|
||||
System.out.println(message);
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.CollectionType;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.FieldOption;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyFactoryDataProcessor;
|
||||
|
||||
@Component (service = EntaxyFactoryDataProcessorService.class, immediate = true)
|
||||
public class EntaxyFactoryDataProcessorService implements EntaxyFactoryDataProcessor {
|
||||
|
||||
private static EntaxyFactoryDataProcessorService _INSTANCE = null;
|
||||
|
||||
public static EntaxyFactoryDataProcessorService getInstance() {
|
||||
return _INSTANCE;
|
||||
}
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MULTIPLE, collectionType = CollectionType.SERVICE, fieldOption = FieldOption.UPDATE,
|
||||
policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY, service = EntaxyFactoryDataProcessor.class)
|
||||
List<EntaxyFactoryDataProcessor> processors;
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
_INSTANCE = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object processDefaultValue(Object currentValue) {
|
||||
Object result = currentValue;
|
||||
for (EntaxyFactoryDataProcessor p: processors) {
|
||||
result = p.processDefaultValue(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.DIRECTIVES.OVERRIDE_MODE;
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactoryUtils;
|
||||
import ru.entaxy.platform.base.support.JSONUtils;
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyProducerService;
|
||||
|
||||
public class InstructionsHelper {
|
||||
|
||||
public static final String DEFAULT_INSTRUCTIONS = "{'validate':{}}";
|
||||
public static final String LIFECYCLE_DIRECTIVE = EntaxyProducerService.DIRECTIVES.LIFECYCLE;
|
||||
|
||||
protected JsonObject lifecyclesOrigin;
|
||||
|
||||
protected Map<String, JsonObject> lifecycles = new HashMap<>();
|
||||
|
||||
public InstructionsHelper(JsonObject lifecycles) {
|
||||
super();
|
||||
this.lifecyclesOrigin = lifecycles.deepCopy();
|
||||
fillMap(this.lifecyclesOrigin);
|
||||
}
|
||||
|
||||
protected void fillMap(JsonObject origin) {
|
||||
for (Entry<String, JsonElement> entry: origin.entrySet())
|
||||
if (entry.getValue().isJsonObject())
|
||||
this.lifecycles.put(entry.getKey(), entry.getValue().getAsJsonObject().deepCopy());
|
||||
}
|
||||
|
||||
public String prepareInstructions(String originalInstructions) {
|
||||
JsonObject origin = JSONUtils.getJsonRootObject(originalInstructions);
|
||||
JsonObject result = new JsonObject();
|
||||
if (origin.has(LIFECYCLE_DIRECTIVE)) {
|
||||
JsonElement directiveValue = origin.get(LIFECYCLE_DIRECTIVE);
|
||||
List<String> lcIdToApply = new ArrayList<>();
|
||||
List<JsonObject> lcToApply = new ArrayList<>();
|
||||
if (directiveValue.isJsonPrimitive())
|
||||
lcIdToApply.add(directiveValue.getAsString());
|
||||
if (directiveValue.isJsonArray()) {
|
||||
JsonArray ja = directiveValue.getAsJsonArray();
|
||||
for (int i=0; i<ja.size(); i++)
|
||||
lcIdToApply.add(ja.get(i).getAsString());
|
||||
}
|
||||
origin.remove(LIFECYCLE_DIRECTIVE);
|
||||
for (String id: lcIdToApply)
|
||||
if (this.lifecycles.containsKey(id))
|
||||
EntaxyFactoryUtils.processObjectOverriding(
|
||||
result
|
||||
, this.lifecycles.get(id)
|
||||
, OVERRIDE_MODE.UPDATE);
|
||||
}
|
||||
EntaxyFactoryUtils.processObjectOverriding(
|
||||
result
|
||||
, origin
|
||||
, OVERRIDE_MODE.UPDATE);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.support;
|
||||
|
||||
public abstract class AbstractConsumerAwareMetadataStorage implements MetadataStorage {
|
||||
|
||||
protected String prefix = "";
|
||||
protected MetadataStorageConsumer consumer;
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public MetadataStorageConsumer getConsumer() {
|
||||
return consumer;
|
||||
}
|
||||
|
||||
public void setConsumer(MetadataStorageConsumer consumer) {
|
||||
this.consumer = consumer;
|
||||
if (this.consumer != null)
|
||||
this.consumer.addStrorage(getPrefix(), this);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.support;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
|
||||
public class ExchangeEnricher implements Processor, MetadataStorageConsumer {
|
||||
|
||||
protected Map<MetadataStorage, String> map = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void addStrorage(String prefix, MetadataStorage storage) {
|
||||
this.map.put(storage, prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
|
||||
for (MetadataStorage ms: map.keySet()) {
|
||||
Map<String, Object> allData = ms.getAllData();
|
||||
String prefix = map.get(ms);
|
||||
for (Entry<String, Object> entry: allData.entrySet()) {
|
||||
exchange.getIn().setHeader(prefix + entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.support;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface MetadataStorage {
|
||||
|
||||
Map<String, String> getStrings();
|
||||
|
||||
Map<String, Boolean> getBooleans();
|
||||
|
||||
Map<String, Number> getNumbers();
|
||||
|
||||
Map<String, Object> getAllData();
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.support;
|
||||
|
||||
public interface MetadataStorageConsumer {
|
||||
|
||||
public void addStrorage(String prefix, MetadataStorage storage);
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.support;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class MetadataStorageEmpty implements MetadataStorage {
|
||||
|
||||
@Override
|
||||
public Map<String, String> getStrings() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getBooleans() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Number> getNumbers() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAllData() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.support;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MetadataStorageImpl extends AbstractConsumerAwareMetadataStorage implements MetadataStorage {
|
||||
|
||||
protected Map<String, String> strings;
|
||||
protected Map<String, Boolean> booleans;
|
||||
protected Map<String, Number> numbers;
|
||||
|
||||
@Override
|
||||
public Map<String, String> getStrings() {
|
||||
return strings;
|
||||
}
|
||||
|
||||
public void setStrings(Map<String, String> strings) {
|
||||
this.strings = strings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getBooleans() {
|
||||
return booleans;
|
||||
}
|
||||
|
||||
public void setBooleans(Map<String, Boolean> booleans) {
|
||||
this.booleans = booleans;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Number> getNumbers() {
|
||||
return numbers;
|
||||
}
|
||||
|
||||
public void setNumbers(Map<String, Number> numbers) {
|
||||
this.numbers = numbers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAllData() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
result.putAll(strings);
|
||||
result.putAll(booleans);
|
||||
result.putAll(numbers);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.support;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MetadataStorageWrapper extends AbstractConsumerAwareMetadataStorage implements MetadataStorage {
|
||||
|
||||
protected MetadataStorage origin;
|
||||
protected MetadataStorage empty = new MetadataStorageEmpty();
|
||||
|
||||
public MetadataStorage getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
public void setOrigin(MetadataStorage origin) {
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
protected MetadataStorage getStorage() {
|
||||
if (origin != null)
|
||||
return origin;
|
||||
return empty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getStrings() {
|
||||
return getStorage().getStrings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getBooleans() {
|
||||
return getStorage().getBooleans();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Number> getNumbers() {
|
||||
return getStorage().getNumbers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAllData() {
|
||||
return getStorage().getAllData();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,224 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producer-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.wrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.CollectionType;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.core.producer.wrapper.AbstractFactoryWrapper.GenerationProcessor;
|
||||
|
||||
@Component(service = GenerationProcessorService.class, immediate = true)
|
||||
public class GenerationProcessorService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GenerationProcessorService.class);
|
||||
|
||||
public static final String FACTORY_PLUGIN_FIELD = "generation.plugins";
|
||||
|
||||
private static GenerationProcessorService INSTANCE;
|
||||
|
||||
public static GenerationProcessorService getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
protected static enum PLUGIN_STATUS {
|
||||
DENIED,
|
||||
ALLOWED,
|
||||
UNDEFINED
|
||||
}
|
||||
|
||||
protected static class GenerationProcessorHelper {
|
||||
|
||||
ServiceReference<GenerationProcessor> ref;
|
||||
|
||||
String id;
|
||||
List<String> factoryTypes = new ArrayList<>();
|
||||
|
||||
public GenerationProcessorHelper(ServiceReference<GenerationProcessor> ref) {
|
||||
this.ref = ref;
|
||||
|
||||
this.id = getId(ref);
|
||||
if (!CommonUtils.isValid(this.id))
|
||||
return;
|
||||
|
||||
Object obj = ref.getProperty(GenerationProcessor.PROP_FACTORY_TYPE);
|
||||
|
||||
if (obj == null)
|
||||
return;
|
||||
|
||||
if (obj instanceof String) {
|
||||
factoryTypes.add(obj.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj instanceof String[]) {
|
||||
String[] data = (String[])obj;
|
||||
factoryTypes.addAll(Arrays.asList(data));
|
||||
}
|
||||
|
||||
if (obj instanceof List) {
|
||||
for (Object item: (List)obj)
|
||||
if (item!=null)
|
||||
factoryTypes.add(item.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static String getId(ServiceReference<GenerationProcessor> ref) {
|
||||
Object obj = ref.getProperty(GenerationProcessor.PROP_PROCESSOR_ID);
|
||||
if (obj != null)
|
||||
return obj.toString();
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public PLUGIN_STATUS getStatusForType(String factoryType) {
|
||||
|
||||
PLUGIN_STATUS result = PLUGIN_STATUS.UNDEFINED;
|
||||
|
||||
for (String type: factoryTypes) {
|
||||
boolean denied = type.startsWith("!");
|
||||
if (denied)
|
||||
type = type.substring(1);
|
||||
|
||||
if (matches(factoryType, type)) {
|
||||
if (denied)
|
||||
return PLUGIN_STATUS.DENIED;
|
||||
else
|
||||
result = PLUGIN_STATUS.ALLOWED;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected boolean matches(String value, String template) {
|
||||
|
||||
String expression = template.replaceAll("\\*", ".*");
|
||||
return Pattern.matches(expression, value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Map<String, GenerationProcessorHelper> processors = new HashMap<>();
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
@Reference (unbind = "removeProcessor", cardinality = ReferenceCardinality.MULTIPLE
|
||||
, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY
|
||||
, service = GenerationProcessor.class, collectionType = CollectionType.REFERENCE)
|
||||
public void addProcessor(ServiceReference<GenerationProcessor> ref) {
|
||||
String id = GenerationProcessorHelper.getId(ref);
|
||||
if (!CommonUtils.isValid(id))
|
||||
return;
|
||||
processors.put(id, new GenerationProcessorHelper(ref));
|
||||
}
|
||||
|
||||
public void removeProcessor(ServiceReference<GenerationProcessor> ref) {
|
||||
String id = GenerationProcessorHelper.getId(ref);
|
||||
if (!CommonUtils.isValid(id))
|
||||
return;
|
||||
processors.remove(id);
|
||||
}
|
||||
|
||||
protected PLUGIN_STATUS getEffectiveStatus(PLUGIN_STATUS st1, PLUGIN_STATUS st2) {
|
||||
List<PLUGIN_STATUS> list = new ArrayList<>() {{
|
||||
add(st1);
|
||||
add(st2);
|
||||
}};
|
||||
if (list.contains(PLUGIN_STATUS.DENIED))
|
||||
return PLUGIN_STATUS.DENIED;
|
||||
if (list.contains(PLUGIN_STATUS.ALLOWED))
|
||||
return PLUGIN_STATUS.ALLOWED;
|
||||
return PLUGIN_STATUS.UNDEFINED;
|
||||
}
|
||||
|
||||
public List<ServiceReference<GenerationProcessor>> getProcessorsRefs(EntaxyFactory factory){
|
||||
List<ServiceReference<GenerationProcessor>> result = new ArrayList<>();
|
||||
|
||||
Map<String, PLUGIN_STATUS> factoryData = getStatusFromFactory(factory);
|
||||
String type = factory.getType();
|
||||
|
||||
for (String pluginId: processors.keySet()) {
|
||||
GenerationProcessorHelper helper = processors.get(pluginId);
|
||||
PLUGIN_STATUS status = getEffectiveStatus(factoryData.get(pluginId)
|
||||
, helper.getStatusForType(type));
|
||||
if (PLUGIN_STATUS.ALLOWED.equals(status))
|
||||
result.add(helper.ref);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Map<String, PLUGIN_STATUS> getStatusFromFactory(EntaxyFactory factory) {
|
||||
|
||||
Map<String, PLUGIN_STATUS> result = new HashMap<>();
|
||||
|
||||
Map<String, Object> typeInfo = factory.getTypeInfo();
|
||||
if (typeInfo.containsKey(FACTORY_PLUGIN_FIELD)) {
|
||||
List<String> plugins = new ArrayList<>();
|
||||
Object obj = typeInfo.get(FACTORY_PLUGIN_FIELD);
|
||||
if (obj != null) {
|
||||
if (obj instanceof String)
|
||||
plugins.add(obj.toString());
|
||||
else if (obj instanceof Object[]) {
|
||||
List<Object> objList = Arrays.asList((Object[])obj);
|
||||
for (Object item: objList)
|
||||
if (item!=null)
|
||||
plugins.add(item.toString());
|
||||
} else if (obj instanceof List)
|
||||
for (Object item: (List)obj)
|
||||
if (item != null)
|
||||
plugins.add(item.toString());
|
||||
}
|
||||
for (String plugin: plugins) {
|
||||
if (plugin.startsWith("!")) {
|
||||
plugin = plugin.substring(1);
|
||||
result.put(plugin, PLUGIN_STATUS.DENIED);
|
||||
} else {
|
||||
result.put(plugin, PLUGIN_STATUS.ALLOWED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
{
|
||||
"*": {
|
||||
"position": "inside_first"
|
||||
},
|
||||
"fragment": {
|
||||
"isTransparent": true
|
||||
},
|
||||
"reference": {
|
||||
"position": "inside_first",
|
||||
"unique": ["id"],
|
||||
"conflict": "ignore" /*[ignore, replace]*/
|
||||
},
|
||||
"route": {
|
||||
"targetNodeName": "camelContext",
|
||||
"position": "inside_last",
|
||||
"createTargetNode": true,
|
||||
"targetNodeXML": "<camelContext xmlns=\"http://camel.apache.org/schema/blueprint\" />"
|
||||
}
|
||||
}
|
@ -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.
|
@ -0,0 +1,85 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>object-producing</artifactId>
|
||||
<version>1.8.3</version>
|
||||
</parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core.object-producing</groupId>
|
||||
<artifactId>object-producing-resources-support</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>ENTAXY :: PLATFORM :: CORE :: OBJECT PRODUCING :: RESOURCES SUPPORT</name>
|
||||
<description>ENTAXY :: PLATFORM :: CORE :: OBJECT PRODUCING :: RESOURCES SUPPORT</description>
|
||||
|
||||
<properties>
|
||||
<bundle.osgi.export.pkg>ru.entaxy.platform.core.producer.resources*</bundle.osgi.export.pkg>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>
|
||||
ru.entaxy.esb.platform.runtime.core.object-producing
|
||||
</groupId>
|
||||
<artifactId>object-producer-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>
|
||||
ru.entaxy.esb.platform.runtime.core.object-producing
|
||||
</groupId>
|
||||
<artifactId>object-producer-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>
|
||||
ru.entaxy.esb.platform.runtime.base.resources
|
||||
</groupId>
|
||||
<artifactId>resources-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>
|
||||
ru.entaxy.esb.platform.runtime.base.connecting.generator
|
||||
</groupId>
|
||||
<artifactId>generator-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.servicemix.bundles</groupId>
|
||||
<artifactId>org.apache.servicemix.bundles.saxon</artifactId>
|
||||
<version>${servicemix-saxon-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>${maven-bundle-plugin.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Entaxy-Factory-Provider>true</Entaxy-Factory-Provider>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,37 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import ru.entaxy.platform.core.producer.resources.generator.GeneratedResourceWrapper;
|
||||
|
||||
public class DeployableResource extends ResourceDescriptor {
|
||||
|
||||
public Object resourceData;
|
||||
public String resourceType;
|
||||
|
||||
public DeployableResource(Map<String, Object> properties) {
|
||||
super(properties);
|
||||
resourceData = properties.get(GeneratedResourceWrapper.OBJECT_KEY);
|
||||
resourceType = properties.getOrDefault("type", "unknown").toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface EntaxyResourceProcessor {
|
||||
|
||||
String PROP_PROCESSOR = "processor";
|
||||
|
||||
String getName();
|
||||
Object process(Object value, Map<String, Object> properties);
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface EntaxyResourceProcessorService {
|
||||
|
||||
Object process(Object value, Map<String, Object> properties);
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
public interface EntaxyResourceStringFormatter {
|
||||
|
||||
String getName();
|
||||
String format(String value);
|
||||
String unformat(String value);
|
||||
|
||||
}
|
@ -0,0 +1,242 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
import ru.entaxy.esb.resources.EntaxyResourceService;
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject.FIELDS;
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.FACTORY;
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.CONFIGURATION.OUTPUTS;
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactory.FieldInfo;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.base.support.JSONUtils;
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyProducerService;
|
||||
import ru.entaxy.platform.core.producer.api.ExecutionPlan.ExecutionPlanUpdate;
|
||||
import ru.entaxy.platform.core.producer.api.ProducerResult;
|
||||
import ru.entaxy.platform.core.producer.api.ProducerResult.CommandResult;
|
||||
import ru.entaxy.platform.core.producer.api.ProducingCommandExecutor;
|
||||
import ru.entaxy.platform.core.producer.executor.AbstractCommandExecutor;
|
||||
import ru.entaxy.platform.core.producer.executor.CommandExecutor;
|
||||
import ru.entaxy.platform.core.producer.executor.objectmodel.Calculation;
|
||||
import ru.entaxy.platform.core.producer.executor.objectmodel.FactoredObject;
|
||||
import ru.entaxy.platform.core.producer.executor.objectmodel.FactoredObjectProxy;
|
||||
import ru.entaxy.platform.core.producer.executor.objectmodel.ObjectModel;
|
||||
|
||||
@Component(service = ProducingCommandExecutor.class, immediate = true)
|
||||
@CommandExecutor(id = "process-resources", predecessors = {"enrich"}, descendants = {"validate"})
|
||||
public class ProcessResourcesCommand extends AbstractCommandExecutor implements ProducingCommandExecutor {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ProcessResourcesCommand.class);
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY)
|
||||
EntaxyProducerService entaxyProducerServiceLocal;
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY)
|
||||
EntaxyResourceService entaxyResourceService;
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY)
|
||||
ResourceDataProcessor resourceDataProcessor;
|
||||
|
||||
public ProcessResourcesCommand() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
protected ProcessResourcesCommand(EntaxyProducerService entaxyProducerService) {
|
||||
super(entaxyProducerService);
|
||||
}
|
||||
|
||||
@Activate
|
||||
public void activate(ComponentContext componentContext) {
|
||||
this.entaxyProducerService = this.entaxyProducerServiceLocal;
|
||||
this.entaxyProducerService.registerCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doExecute(ProducerResult currentResult, CommandResult commandResult,
|
||||
Map<String, Object> instructions) throws Exception {
|
||||
|
||||
ObjectModel objectModel = currentResult.findResultObject(ObjectModel.class);
|
||||
objectModel.startTracking();
|
||||
|
||||
JsonObject incomingJson = objectModel.getJsonCurrent().deepCopy();
|
||||
|
||||
for (FactoredObject fo: objectModel.objects) {
|
||||
|
||||
// skip proxies
|
||||
if (fo instanceof FactoredObjectProxy)
|
||||
continue;
|
||||
|
||||
String factoryId = fo.factoryId;
|
||||
|
||||
EntaxyFactory factory = entaxyProducerService.findFactoryById(factoryId);
|
||||
|
||||
JsonObject objectOrigin = fo.origin;
|
||||
|
||||
|
||||
if (JSONUtils.setValue(objectOrigin, FIELDS.PROPERTIES, new JsonObject(), true)) {
|
||||
printOutput("[DIRTY] CREATED 'properties' for [" + fo.getObjectId() + "/" + fo.getObjectType() + "]");
|
||||
objectModel.setDirty();
|
||||
}
|
||||
|
||||
JsonObject objectProperties = objectOrigin.get(FIELDS.PROPERTIES).getAsJsonObject();
|
||||
|
||||
String outputType = CommonUtils.isValid(fo.getOutputType())
|
||||
?fo.getOutputType()
|
||||
:factory.getDefaultOutput()!=null
|
||||
?factory.getDefaultOutput().getType()
|
||||
:OUTPUTS.OUTPUT_TYPE_INIT;
|
||||
|
||||
List<FieldInfo> factoryFields = factory.getFields(outputType);
|
||||
|
||||
log.debug("\n FIELDS FOR " + factory.getId() + "/" + outputType + ":" + factoryFields.size());
|
||||
|
||||
// if the value is JsonObject
|
||||
// and represents some resource
|
||||
// we first resolve it to actual value
|
||||
JsonObject newProperties = new JsonObject();
|
||||
for (Entry<String, JsonElement> entry: objectProperties.entrySet()) {
|
||||
|
||||
if (entry.getValue().isJsonObject())
|
||||
if (entry.getValue().getAsJsonObject().has(ResourceDataProcessor.ENTAXY_RESOURCE_KEY)) {
|
||||
JsonElement jsonDescriptor = entry.getValue().getAsJsonObject().get(ResourceDataProcessor.ENTAXY_RESOURCE_KEY);
|
||||
ResourceDescriptor resourceDescriptor = ResourceDescriptor.fromJson(jsonDescriptor);
|
||||
if (resourceDescriptor == null)
|
||||
continue;
|
||||
Object newData = resourceDataProcessor.getResourceDataFromDescriptor(resourceDescriptor);
|
||||
JsonElement newValue = (new Gson()).toJsonTree(newData);
|
||||
|
||||
newProperties.add(entry.getKey(), newValue);
|
||||
}
|
||||
}
|
||||
for (Entry<String, JsonElement> entry: newProperties.entrySet()) {
|
||||
if (JSONUtils.setValue(objectProperties, entry.getKey(), entry.getValue().deepCopy(), false)) {
|
||||
printOutput("[DIRTY] UPDATED " + entry.getKey() + " for [" + fo.getObjectId() + "/" + fo.getObjectType() + "]");
|
||||
objectModel.setDirty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// for the field defined as a resource
|
||||
// we must make an object
|
||||
for (FieldInfo fi: factoryFields) {
|
||||
log.debug("\n--> FIELD :: " + fi.getName());
|
||||
log.debug("\n" + objectProperties.toString());
|
||||
JsonObject jsonFi = fi.getJsonOrigin();
|
||||
if (!objectProperties.has(fi.getName()))
|
||||
continue;
|
||||
log.debug("\nORIGIN:\n" + fi.getJsonOrigin().toString());
|
||||
if (jsonFi.has(ResourceDataProcessor.ENTAXY_RESOURCE_KEY)) {
|
||||
log.debug("\n--> FIELD :: " + fi.getName() + " IS A RESOURCE");
|
||||
ResourceDescriptor descriptor = ResourceDescriptor.fromJson(jsonFi.get(ResourceDataProcessor.ENTAXY_RESOURCE_KEY));
|
||||
if (descriptor == null)
|
||||
continue;
|
||||
JsonElement currentValue = objectProperties.get(fi.getName());
|
||||
if (currentValue.isJsonObject()) {
|
||||
JsonObject currentObject = currentValue.getAsJsonObject();
|
||||
if (currentObject.has("isRef")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
JsonElement newValueElement = jsonFi.get(ResourceDataProcessor.ENTAXY_RESOURCE_KEY);
|
||||
if (!newValueElement.isJsonObject())
|
||||
continue;
|
||||
JsonObject properties = newValueElement.getAsJsonObject().deepCopy();
|
||||
|
||||
// add default location if not set
|
||||
if (!properties.has(ResourceDataProcessor.PROP_LOCATION)) {
|
||||
JsonObject locationData = new JsonObject();
|
||||
locationData.addProperty(Calculation.FIELD_IS_CALCULATED, true);
|
||||
locationData.addProperty("lazy", true);
|
||||
locationData.addProperty("expression"
|
||||
, "object-resources/${#OWNER#.objectId}/" + fi.getName() + "." + fi.getType().split(":")[0]);
|
||||
properties.add(ResourceDataProcessor.PROP_LOCATION, locationData);
|
||||
}
|
||||
|
||||
properties.add("content", currentValue);
|
||||
properties.addProperty("type", fi.getType());
|
||||
JsonObject newValue = new JsonObject();
|
||||
newValue.addProperty(FACTORY.TYPE, "entaxy.resource");
|
||||
newValue.addProperty(EntaxyObject.FIELDS.FACTORY_ID, "entaxy-resource");
|
||||
|
||||
JsonObject refConfig = new JsonObject();
|
||||
refConfig.addProperty(EntaxyObject.FIELDS.REF_FIELD, "content");
|
||||
refConfig.addProperty("generated.targetType", Generated.GENERATED_TYPE_BLUEPRINT_FRAGMENT);
|
||||
newValue.add("refConfig", refConfig);
|
||||
|
||||
// newValue.addProperty("__skip", true);
|
||||
newValue.add(FIELDS.PROPERTIES, properties);
|
||||
if (jsonFi.has("config") && jsonFi.get("config").isJsonObject()) {
|
||||
JsonObject configObject = jsonFi.get("config").getAsJsonObject();
|
||||
for (Entry<String, JsonElement> entry: configObject.entrySet()) {
|
||||
if (!newValue.has(entry.getKey()))
|
||||
newValue.add(entry.getKey(), entry.getValue().deepCopy());
|
||||
}
|
||||
}
|
||||
JSONUtils.setValue(objectProperties, fi.getName(), newValue, false);
|
||||
objectModel.setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (objectModel.stopTracking()) {
|
||||
|
||||
// remove ##embedded
|
||||
for (FactoredObject fo: objectModel.objects)
|
||||
fo.origin.remove(FactoredObject.EMBEDDED_FIELD);
|
||||
|
||||
|
||||
commandResult.planUpdate = ExecutionPlanUpdate.create()
|
||||
// .updateInstructions().target("enrich").value("skip", true).complete()
|
||||
.reset().target("analyze").complete();
|
||||
}
|
||||
|
||||
JsonObject outgoingJson = objectModel.getJsonCurrent();
|
||||
|
||||
printOutput("\n== INCOMING JSON ==\n");
|
||||
printOutput(incomingJson.toString());
|
||||
printOutput("\n== OUTGOING JSON ==\n");
|
||||
printOutput(outgoingJson.toString());
|
||||
|
||||
commandResult.resultObject(outgoingJson);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyFactoryDataProcessor;
|
||||
|
||||
public interface ResourceDataProcessor extends EntaxyFactoryDataProcessor {
|
||||
|
||||
String ENTAXY_RESOURCE_KEY = ResourceProducer.DIRECTIVES.RESOURCE;
|
||||
|
||||
String PROP_PROVIDER = "provider";
|
||||
String PROP_LOCATION = "location";
|
||||
String PROP_END_TYPE = "endType";
|
||||
String PROP_FORMAT = "format";
|
||||
|
||||
Object getResourceDataFromDescriptor(ResourceDescriptor descriptor);
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
|
||||
public class ResourceDescriptor {
|
||||
|
||||
static public final String RESOURCE_TYPE_PREFIX = "resource:";
|
||||
|
||||
public static ResourceDescriptor fromJson(JsonElement element) {
|
||||
if (element == null)
|
||||
return null;
|
||||
if (!element.isJsonObject())
|
||||
return null;
|
||||
return new ResourceDescriptor(element.getAsJsonObject());
|
||||
}
|
||||
|
||||
public static ResourceDescriptor fromMap(Map<String, Object> properties) {
|
||||
return new ResourceDescriptor(properties);
|
||||
}
|
||||
|
||||
|
||||
protected JsonObject origin;
|
||||
|
||||
public String provider;
|
||||
public String location;
|
||||
public String endType;
|
||||
public String format;
|
||||
|
||||
public ResourceDescriptor(JsonObject jsonObject) {
|
||||
this.origin = jsonObject;
|
||||
loadData();
|
||||
}
|
||||
|
||||
public ResourceDescriptor(Map<String, Object> properties) {
|
||||
this.origin = new JsonObject();
|
||||
loadDataFromMap(properties);
|
||||
}
|
||||
|
||||
protected void loadData() {
|
||||
if (this.origin.has(ResourceDataProcessor.PROP_PROVIDER))
|
||||
this.provider = this.origin.get(ResourceDataProcessor.PROP_PROVIDER).getAsString();
|
||||
if (this.origin.has(ResourceDataProcessor.PROP_LOCATION))
|
||||
if (this.origin.get(ResourceDataProcessor.PROP_LOCATION).isJsonPrimitive())
|
||||
this.location = this.origin.get(ResourceDataProcessor.PROP_LOCATION).getAsString();
|
||||
if (this.origin.has(ResourceDataProcessor.PROP_END_TYPE))
|
||||
this.endType = this.origin.get(ResourceDataProcessor.PROP_END_TYPE).getAsString();
|
||||
if (this.origin.has(ResourceDataProcessor.PROP_FORMAT))
|
||||
this.format = this.origin.get(ResourceDataProcessor.PROP_FORMAT).getAsString();
|
||||
}
|
||||
|
||||
protected void loadDataFromMap(Map<String, Object> properties) {
|
||||
this.provider = properties.getOrDefault(ResourceDataProcessor.PROP_PROVIDER, "default").toString();
|
||||
this.location = properties.getOrDefault(ResourceDataProcessor.PROP_LOCATION, "").toString();
|
||||
this.endType = properties.getOrDefault(ResourceDataProcessor.PROP_END_TYPE, "").toString();
|
||||
this.format = properties.getOrDefault(ResourceDataProcessor.PROP_FORMAT, "").toString();
|
||||
};
|
||||
|
||||
public String getResourceUrl() {
|
||||
return (CommonUtils.isValid(provider)?provider+":":"") + location;
|
||||
}
|
||||
|
||||
public boolean isReturnResource() {
|
||||
return !CommonUtils.isValid(endType) || "resource".equalsIgnoreCase(endType);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
import ru.entaxy.esb.resources.EntaxyResource;
|
||||
import ru.entaxy.esb.resources.EntaxyResourceService;
|
||||
import ru.entaxy.platform.core.producer.executor.builder.BuiltObject;
|
||||
import ru.entaxy.platform.core.producer.executor.builder.DefaultBuiltObject;
|
||||
import ru.entaxy.platform.core.producer.executor.builder.ObjectBuilder;
|
||||
import ru.entaxy.platform.core.producer.executor.deployer.DeployedObject;
|
||||
import ru.entaxy.platform.core.producer.executor.deployer.ObjectDeployer;
|
||||
import ru.entaxy.platform.core.producer.executor.support.LocalPrintOutput;
|
||||
|
||||
@Component(service = {ObjectBuilder.class, ObjectDeployer.class})
|
||||
public class ResourceObjectSupport implements ObjectBuilder, ObjectDeployer {
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY)
|
||||
EntaxyResourceService entaxyResourceService;
|
||||
|
||||
/*
|
||||
* ObjectBuilder
|
||||
*/
|
||||
@Override
|
||||
public boolean isBuildable(Generated generated) {
|
||||
return generated.getType().startsWith(ResourceDescriptor.RESOURCE_TYPE_PREFIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltObject build(Generated generated, Map<String, Object> instructions) throws Exception {
|
||||
if (!isBuildable(generated))
|
||||
return null;
|
||||
|
||||
LocalPrintOutput printer = new LocalPrintOutput(instructions);
|
||||
printer.printOutput(" = GENERATED PROPERTIES");
|
||||
for (Entry<String, Object> entry: generated.getProperties().entrySet()) {
|
||||
printer.printOutput(" :: " + entry.getKey() + " = [\n"
|
||||
+ (entry.getValue()==null?"":entry.getValue().toString())
|
||||
+ "\n]");
|
||||
}
|
||||
printer.printOutput(" = /GENERATED PROPERTIES");
|
||||
return new DefaultBuiltObject(new DeployableResource(generated.getProperties()));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* ObjectDeployer
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean isDeployable(BuiltObject object) {
|
||||
return object.getObject() instanceof DeployableResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeployedObject deploy(BuiltObject object, Map<String, Object> instructions) throws Exception {
|
||||
if (!isDeployable(object))
|
||||
return null;
|
||||
LocalPrintOutput printer = new LocalPrintOutput(instructions);
|
||||
|
||||
DeployableResource dr = (DeployableResource)object.getObject();
|
||||
printer.printOutput(" = RESOURCE TO DEPLOY");
|
||||
printer.printOutput(dr.getResourceUrl() + " [" + dr.resourceType + "/" + dr.endType + "]");
|
||||
|
||||
EntaxyResource resource = entaxyResourceService.getResource(dr.getResourceUrl());
|
||||
resource.save(getInputStream(dr));
|
||||
|
||||
printer.printOutput(" :: DEPLOYED");
|
||||
|
||||
// nothing to do with resource in further phases
|
||||
return null;
|
||||
}
|
||||
|
||||
protected InputStream getInputStream(DeployableResource res) {
|
||||
if ((res==null) || (res.resourceData == null))
|
||||
return getDefaultInputStream();
|
||||
if ("String".equals(res.endType))
|
||||
return IOUtils.toInputStream(res.resourceData.toString());
|
||||
// TODO support other resource types
|
||||
return getDefaultInputStream();
|
||||
|
||||
}
|
||||
|
||||
protected InputStream getDefaultInputStream() {
|
||||
return IOUtils.toInputStream("");
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
import org.osgi.service.component.annotations.CollectionType;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
|
||||
import ru.entaxy.platform.base.objects.factory.EntaxyFactory;
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyProducer;
|
||||
import ru.entaxy.platform.core.producer.impl.CommonObjectProducer;
|
||||
import ru.entaxy.platform.core.producer.impl.EntaxyProducerInfo;
|
||||
import ru.entaxy.platform.core.producer.wrapper.AbstractFactoryWrapper;
|
||||
import ru.entaxy.platform.core.producer.wrapper.DefaultFactoryWrapper;
|
||||
|
||||
@Component(service = {EntaxyProducer.class}, immediate = true)
|
||||
@EntaxyProducerInfo(supportedTypes = {"entaxy.resource"})
|
||||
public class ResourceProducer extends CommonObjectProducer implements EntaxyProducer {
|
||||
|
||||
public static interface DIRECTIVES {
|
||||
String RESOURCE = "@RESOURCE";
|
||||
}
|
||||
|
||||
public static final String PROP_CONTENT = "content";
|
||||
public static final String PROP_PREPROCESS = "preprocess";
|
||||
|
||||
@Reference(bind = "addFactory", unbind = "removeFactory", cardinality = ReferenceCardinality.MULTIPLE
|
||||
, collectionType = CollectionType.SERVICE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
|
||||
public void addFactory(EntaxyFactory factory) {
|
||||
doAddFactory(factory);
|
||||
}
|
||||
|
||||
// WE MUST DECLARE IT for @Reference annotation processor
|
||||
@Override
|
||||
public void removeFactory(EntaxyFactory factory) {
|
||||
super.removeFactory(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractFactoryWrapper doAddFactory(EntaxyFactory factory) {
|
||||
return super.doAddFactory(factory, DefaultFactoryWrapper.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources;
|
||||
|
||||
public interface StringFormatterService {
|
||||
|
||||
String format(String value, String[] formatters);
|
||||
String unformat(String value, String[] formatters);
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources.formatters;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
|
||||
import ru.entaxy.platform.core.producer.resources.EntaxyResourceStringFormatter;
|
||||
|
||||
@Component (service = EntaxyResourceStringFormatter.class, immediate = true)
|
||||
public class Base64Formatter implements EntaxyResourceStringFormatter {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "base64";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(String value) {
|
||||
return new String(Base64.getEncoder().encode(value.getBytes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unformat(String value) {
|
||||
return new String(Base64.getDecoder().decode(value));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources.generator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
import ru.entaxy.platform.core.producer.resources.ResourceDescriptor;
|
||||
|
||||
public class GeneratedResourceWrapper implements Generated {
|
||||
|
||||
public static final String OBJECT_KEY = "#_object";
|
||||
|
||||
protected Map<String, Object> properties = new HashMap<>();
|
||||
|
||||
public GeneratedResourceWrapper (Map<String, Object> props) {
|
||||
this.properties.putAll(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return this.properties.getOrDefault("generated.targetType",
|
||||
ResourceDescriptor.RESOURCE_TYPE_PREFIX + properties.getOrDefault("type", "unknown")).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject() {
|
||||
return this.properties.get(OBJECT_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources.generator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Deactivate;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.AbstractSelfPublishGenerator;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generator;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.GeneratorService;
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.factory.GeneratorFactory;
|
||||
import ru.entaxy.esb.resources.EntaxyResource;
|
||||
import ru.entaxy.esb.resources.EntaxyResourceService;
|
||||
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessorService;
|
||||
import ru.entaxy.platform.core.producer.resources.ResourceDataProcessor;
|
||||
import ru.entaxy.platform.core.producer.resources.ResourceDescriptor;
|
||||
import ru.entaxy.platform.core.producer.resources.ResourceProducer;
|
||||
import ru.entaxy.platform.core.producer.resources.StringFormatterService;
|
||||
|
||||
@Component(
|
||||
service = {GeneratorService.class},
|
||||
property = {GeneratorService.PROP_GENERATOR_TYPE + "=" + ResourceWrapGenerator.GENERATOR_NAME},
|
||||
immediate = true
|
||||
)
|
||||
public class ResourceWrapGenerator extends AbstractSelfPublishGenerator<ResourceWrapGenerator>
|
||||
implements Generator {
|
||||
|
||||
public static final String GENERATOR_NAME = "resource-wrap";
|
||||
|
||||
protected static EntaxyResourceService ENTAXY_RESOURCE_SERVICE;
|
||||
|
||||
protected static StringFormatterService STRING_FORMATTER_SERVICE;
|
||||
|
||||
protected static EntaxyResourceProcessorService RESOURCE_PROCESSOR_SERVICE;
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY)
|
||||
EntaxyResourceService entaxyResourceService;
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY)
|
||||
StringFormatterService stringFormatterService;
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY)
|
||||
EntaxyResourceProcessorService entaxyResourceProcessorService;
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
GeneratorFactory.register(ResourceWrapGenerator.GENERATOR_NAME, this);
|
||||
ResourceWrapGenerator.ENTAXY_RESOURCE_SERVICE = entaxyResourceService;
|
||||
ResourceWrapGenerator.STRING_FORMATTER_SERVICE = stringFormatterService;
|
||||
ResourceWrapGenerator.RESOURCE_PROCESSOR_SERVICE = entaxyResourceProcessorService;
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
public void deactivate() {
|
||||
GeneratorFactory.unregister(GENERATOR_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generated generate(Map<String, Object> properties) throws Exception {
|
||||
ResourceDescriptor descriptor = ResourceDescriptor.fromMap(properties);
|
||||
String content = null;
|
||||
String object = null;
|
||||
if (properties.containsKey(ResourceProducer.PROP_CONTENT)) {
|
||||
content = properties.get(ResourceProducer.PROP_CONTENT).toString();
|
||||
String[] formatters = descriptor.format.split(",");
|
||||
ArrayUtils.reverse(formatters);
|
||||
object = STRING_FORMATTER_SERVICE.unformat(content, formatters);
|
||||
if (properties.containsKey(ResourceProducer.PROP_PREPROCESS)) {
|
||||
Object pp = properties.get(ResourceProducer.PROP_PREPROCESS);
|
||||
if (pp instanceof List) {
|
||||
List list = (List)pp;
|
||||
for (Object obj: list) {
|
||||
if (obj instanceof Map) {
|
||||
Object result = RESOURCE_PROCESSOR_SERVICE.process(object, (Map<String, Object>)obj);
|
||||
if (result != null)
|
||||
object = result.toString();
|
||||
else
|
||||
object = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EntaxyResource resource = ENTAXY_RESOURCE_SERVICE.getResource(descriptor.getResourceUrl());
|
||||
if (resource.exists()) {
|
||||
object = resource.getAsString();
|
||||
content = STRING_FORMATTER_SERVICE.format(object, descriptor.format.split(","));
|
||||
}
|
||||
}
|
||||
if (object == null)
|
||||
return null;
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.putAll(properties);
|
||||
resultMap.put(ResourceProducer.PROP_CONTENT, content);
|
||||
resultMap.put("#_object", object);
|
||||
return new GeneratedResourceWrapper(resultMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeneratable(Map<String, Object> properties) throws Exception {
|
||||
return properties.containsKey(ResourceDataProcessor.PROP_PROVIDER)
|
||||
&& properties.containsKey(ResourceDataProcessor.PROP_LOCATION);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.CollectionType;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessor;
|
||||
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessorService;
|
||||
|
||||
@Component (service = EntaxyResourceProcessorService.class, immediate = true)
|
||||
public class EntaxyResourceProcessorServiceImpl implements EntaxyResourceProcessorService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(EntaxyResourceProcessorServiceImpl.class);
|
||||
|
||||
protected static EntaxyResourceProcessorService _INSTANCE;
|
||||
|
||||
public static EntaxyResourceProcessorService getInstance() {
|
||||
return _INSTANCE;
|
||||
}
|
||||
|
||||
protected Map<String, EntaxyResourceProcessor> processorsMap = new HashMap<>();
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
_INSTANCE = this;
|
||||
}
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MULTIPLE, collectionType = CollectionType.SERVICE, policy = ReferencePolicy.DYNAMIC
|
||||
, policyOption = ReferencePolicyOption.GREEDY, unbind = "removeProcessor")
|
||||
public void addProcessor(EntaxyResourceProcessor processor) {
|
||||
synchronized (processorsMap) {
|
||||
this.processorsMap.put(processor.getName(), processor);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeProcessor(EntaxyResourceProcessor processor) {
|
||||
synchronized (processorsMap) {
|
||||
this.processorsMap.remove(processor.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object process(Object value, Map<String, Object> properties) {
|
||||
Object val = properties.get(EntaxyResourceProcessor.PROP_PROCESSOR);
|
||||
if (val == null)
|
||||
return value;
|
||||
String processorName = val.toString();
|
||||
if (!processorsMap.containsKey(processorName)) {
|
||||
log.warn("Unknown processor [{}] in [{}]", processorName, properties);
|
||||
return value;
|
||||
}
|
||||
return processorsMap.get(processorName).process(value, properties);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources.impl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.entaxy.esb.resources.EntaxyResource;
|
||||
import ru.entaxy.esb.resources.EntaxyResourceService;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyFactoryDataProcessor;
|
||||
import ru.entaxy.platform.core.producer.resources.ResourceDataProcessor;
|
||||
import ru.entaxy.platform.core.producer.resources.ResourceDescriptor;
|
||||
import ru.entaxy.platform.core.producer.resources.StringFormatterService;
|
||||
|
||||
@Component (service = {EntaxyFactoryDataProcessor.class, ResourceDataProcessor.class}, immediate = true)
|
||||
public class ResourceDataProcessorImpl implements EntaxyFactoryDataProcessor, ResourceDataProcessor {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ResourceDataProcessorImpl.class);
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY)
|
||||
EntaxyResourceService entaxyResourceService;
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY)
|
||||
StringFormatterService stringFormatterService;
|
||||
|
||||
@Override
|
||||
public Object processDefaultValue(Object currentValue) {
|
||||
// log.info("\n-->> PROCESSING :: " + (currentValue==null?"NULL":currentValue.getClass().getName()));
|
||||
if (currentValue == null)
|
||||
return currentValue;
|
||||
ResourceDescriptor descriptor = null;
|
||||
if (currentValue instanceof JsonElement) {
|
||||
// log.info("\n-->> PROCESSING :: JsonElement");
|
||||
if (((JsonElement) currentValue).isJsonObject()) {
|
||||
// log.info("\n-->> PROCESSING :: JsonObject");
|
||||
JsonObject jsonObject = ((JsonElement) currentValue).getAsJsonObject();
|
||||
if (jsonObject.has(ENTAXY_RESOURCE_KEY)) {
|
||||
// log.info("\n-->> PROCESSING :: entaxy-resource");
|
||||
descriptor = ResourceDescriptor.fromJson(jsonObject.get(ENTAXY_RESOURCE_KEY));
|
||||
}
|
||||
}
|
||||
} else if (currentValue instanceof Map) {
|
||||
// log.info("\n-->> PROCESSING :: MAP");
|
||||
if (((Map)currentValue).containsKey(ENTAXY_RESOURCE_KEY)) {
|
||||
Object current = ((Map)currentValue).get(ENTAXY_RESOURCE_KEY);
|
||||
// log.info("\n-->> PROCESSING :: SUBMAP :: " + current.getClass().getName());
|
||||
if (current instanceof Map) {
|
||||
JsonElement je = (new Gson()).toJsonTree(current);
|
||||
// log.info("\n-->> PROCESSING :: JE :: " + je.toString());
|
||||
descriptor = ResourceDescriptor.fromJson(je);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// log.info("\n-->> PROCESSING :: NOT KNOWN");
|
||||
}
|
||||
if (descriptor != null) {
|
||||
Object result = getResourceDataFromDescriptor(descriptor);
|
||||
return result==null?currentValue:result;
|
||||
}
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getResourceDataFromDescriptor(ResourceDescriptor descriptor) {
|
||||
EntaxyResource resource = entaxyResourceService.getResource(descriptor.getResourceUrl());
|
||||
if (resource == null)
|
||||
return null;
|
||||
if (descriptor.isReturnResource())
|
||||
return resource;
|
||||
if (!resource.exists())
|
||||
return null;
|
||||
if ("String".equalsIgnoreCase(descriptor.endType)) {
|
||||
String resourceData = resource.getAsString();
|
||||
String format = descriptor.format;
|
||||
if (CommonUtils.isValid(format)) {
|
||||
log.info("\n FORMAT :: " + format);
|
||||
resourceData = stringFormatterService.format(resourceData, format.split(","));
|
||||
}
|
||||
return resourceData;
|
||||
}
|
||||
return resource.getLocation();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.CollectionType;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
|
||||
import ru.entaxy.platform.core.producer.resources.EntaxyResourceStringFormatter;
|
||||
import ru.entaxy.platform.core.producer.resources.StringFormatterService;
|
||||
|
||||
@Component (service = StringFormatterService.class, immediate = true)
|
||||
public class StringFormatterServiceImpl implements StringFormatterService {
|
||||
|
||||
protected static StringFormatterService _INSTANCE;
|
||||
|
||||
public static StringFormatterService getInstance() {
|
||||
return _INSTANCE;
|
||||
}
|
||||
|
||||
protected Map<String, EntaxyResourceStringFormatter> formattersMap = new HashMap<>();
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
_INSTANCE = this;
|
||||
}
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MULTIPLE, collectionType = CollectionType.SERVICE, policy = ReferencePolicy.DYNAMIC
|
||||
, policyOption = ReferencePolicyOption.GREEDY, unbind = "removeFormatter")
|
||||
public void addFormatter(EntaxyResourceStringFormatter formatter) {
|
||||
synchronized (formattersMap) {
|
||||
this.formattersMap.put(formatter.getName(), formatter);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFormatter(EntaxyResourceStringFormatter formatter) {
|
||||
synchronized (formattersMap) {
|
||||
this.formattersMap.remove(formatter.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(String value, String[] formatters) {
|
||||
String current = value;
|
||||
for (int i=0; i<formatters.length; i++) {
|
||||
String formatter = formatters[i].trim();
|
||||
if (this.formattersMap.containsKey(formatter))
|
||||
current = this.formattersMap.get(formatter).format(current);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unformat(String value, String[] formatters) {
|
||||
String current = value;
|
||||
for (int i=0; i<formatters.length; i++) {
|
||||
String formatter = formatters[i].trim();
|
||||
if (this.formattersMap.containsKey(formatter))
|
||||
current = this.formattersMap.get(formatter).unformat(current);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources.processors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import ru.entaxy.esb.resources.EntaxyResource;
|
||||
import ru.entaxy.esb.resources.EntaxyResourceService;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.base.support.xml.CommonXMLUtils;
|
||||
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessor;
|
||||
|
||||
@Component (service = EntaxyResourceProcessor.class, immediate = true)
|
||||
public class MergeResourceProcessor implements EntaxyResourceProcessor {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MergeResourceProcessor.class);
|
||||
|
||||
public static final String PROP_SOURCE = "source";
|
||||
public static final String PROP_SOURCE_ELEMENT = "sourceElement";
|
||||
public static final String PROP_TARGET_ELEMENT = "targetElement";
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY)
|
||||
EntaxyResourceService entaxyResourceService;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "merge";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object process(Object value, Map<String, Object> properties) {
|
||||
if (value == null)
|
||||
return value;
|
||||
|
||||
Object valueToReturn = null;
|
||||
|
||||
String sourceLocation = properties.getOrDefault(PROP_SOURCE, "").toString();
|
||||
if (!CommonUtils.isValid(sourceLocation)) {
|
||||
log.warn("'source' not defined in [{}]", properties);
|
||||
return value;
|
||||
}
|
||||
|
||||
EntaxyResource resource = entaxyResourceService.getResource(sourceLocation);
|
||||
if (!resource.exists()) {
|
||||
log.warn("Source [{}] not found, was defined in [{}]", sourceLocation, properties);
|
||||
return value;
|
||||
}
|
||||
|
||||
String sourceElement = properties.getOrDefault(PROP_SOURCE_ELEMENT, "").toString();
|
||||
if (!CommonUtils.isValid(sourceElement)) {
|
||||
log.warn("Source element not defined in [{}]", properties);
|
||||
return value;
|
||||
}
|
||||
|
||||
String targetElement = properties.getOrDefault(PROP_TARGET_ELEMENT, "").toString();
|
||||
if (!CommonUtils.isValid(targetElement)) {
|
||||
log.warn("Source element not defined in [{}]", properties);
|
||||
return value;
|
||||
}
|
||||
|
||||
String targetXMLString = value.toString();
|
||||
String sourceXMLString = resource.getAsString();
|
||||
|
||||
try {
|
||||
Document targetDocument = CommonXMLUtils.parseString(false, targetXMLString);
|
||||
Document sourceDocument = CommonXMLUtils.parseString(false, sourceXMLString);
|
||||
|
||||
NodeList nodesToReplace = targetDocument.getElementsByTagName(targetElement);
|
||||
if (nodesToReplace.getLength() == 0)
|
||||
return value;
|
||||
|
||||
NodeList replacements = sourceDocument.getElementsByTagName(sourceElement);
|
||||
if (replacements.getLength() == 0)
|
||||
return value;
|
||||
|
||||
Node replacement = replacements.item(0);
|
||||
NodeList replacementChildren = replacement.getChildNodes();
|
||||
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
|
||||
for (int i=0; i<nodesToReplace.getLength(); i++) {
|
||||
Node toReplace = nodesToReplace.item(i);
|
||||
for (int j=0; j<replacementChildren.getLength(); j++) {
|
||||
Node adopted = targetDocument.adoptNode(replacementChildren.item(j).cloneNode(true));
|
||||
toReplace.getParentNode().insertBefore(adopted, toReplace);
|
||||
}
|
||||
toRemove.add(toReplace);
|
||||
}
|
||||
|
||||
for (Node n: toRemove)
|
||||
n.getParentNode().removeChild(n);
|
||||
|
||||
valueToReturn = CommonXMLUtils.doc2string(targetDocument);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error merging documents", e);
|
||||
return value;
|
||||
}
|
||||
|
||||
return valueToReturn;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources.processors;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.resources.EntaxyResource;
|
||||
import ru.entaxy.esb.resources.EntaxyResourceService;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessor;
|
||||
|
||||
@Component (service = EntaxyResourceProcessor.class, immediate = true)
|
||||
public class XSLTResourceProcessor implements EntaxyResourceProcessor {
|
||||
|
||||
public static final String PROP_SOURCE = "source";
|
||||
public static final String PROP_PARAMETERS = "parameters";
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(XSLTResourceProcessor.class);
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY)
|
||||
EntaxyResourceService entaxyResourceService;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "xslt";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object process(Object value, Map<String, Object> properties) {
|
||||
log.info("XSLT :: processing [{}]", value);
|
||||
|
||||
if (value == null)
|
||||
return value;
|
||||
|
||||
String xsltLocation = properties.getOrDefault(PROP_SOURCE, "").toString();
|
||||
if (!CommonUtils.isValid(xsltLocation)) {
|
||||
log.warn("XSL not defined in [{}]", properties);
|
||||
return value;
|
||||
}
|
||||
|
||||
EntaxyResource resource = entaxyResourceService.getResource(xsltLocation);
|
||||
if (!resource.exists()) {
|
||||
log.warn("XSL [{}] not found, was defined in [{}]", xsltLocation, properties);
|
||||
return value;
|
||||
}
|
||||
|
||||
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
|
||||
TransformerFactory factory = TransformerFactory.newInstance();
|
||||
Source xslt = new StreamSource(resource.getInputStream());
|
||||
Transformer transformer;
|
||||
try {
|
||||
transformer = factory.newTransformer(xslt);
|
||||
} catch (TransformerConfigurationException e) {
|
||||
log.error("Error creating transformer for [" + xsltLocation + "]", e);
|
||||
return value;
|
||||
}
|
||||
|
||||
if (properties.containsKey(PROP_PARAMETERS)) {
|
||||
Object obj = properties.get(PROP_PARAMETERS);
|
||||
if (obj instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>)obj;
|
||||
for (Map.Entry<String, Object> entry: map.entrySet()) {
|
||||
transformer.setParameter(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Source xml = new StreamSource(new StringReader(value.toString()));
|
||||
StringWriter result = new StringWriter();
|
||||
try {
|
||||
transformer.transform(xml, new StreamResult(result));
|
||||
} catch (TransformerException e) {
|
||||
log.error("Error transforming [" + value.toString() + "] with [" + xsltLocation + "]", e);
|
||||
return value;
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-resources-support
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.resources.processors;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.transform.ErrorListener;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
import net.sf.saxon.s9api.QName;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.Serializer;
|
||||
import net.sf.saxon.s9api.XdmAtomicValue;
|
||||
import net.sf.saxon.s9api.XsltCompiler;
|
||||
import net.sf.saxon.s9api.XsltExecutable;
|
||||
import net.sf.saxon.s9api.XsltTransformer;
|
||||
import ru.entaxy.esb.resources.EntaxyResource;
|
||||
import ru.entaxy.esb.resources.EntaxyResourceService;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.core.producer.resources.EntaxyResourceProcessor;
|
||||
|
||||
@Component (service = EntaxyResourceProcessor.class, immediate = true)
|
||||
public class XSLTSaxonResourceProcessor implements EntaxyResourceProcessor {
|
||||
|
||||
public static final String PROP_SOURCE = "source";
|
||||
public static final String PROP_PARAMETERS = "parameters";
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(XSLTSaxonResourceProcessor.class);
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY)
|
||||
EntaxyResourceService entaxyResourceService;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "saxon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object process(Object value, Map<String, Object> properties) {
|
||||
|
||||
log.info("SAXON :: processing [{}]", value);
|
||||
|
||||
if (value == null)
|
||||
return value;
|
||||
|
||||
String xsltLocation = properties.getOrDefault(PROP_SOURCE, "").toString();
|
||||
if (!CommonUtils.isValid(xsltLocation)) {
|
||||
log.warn("XSL not defined in [{}]", properties);
|
||||
return value;
|
||||
}
|
||||
|
||||
EntaxyResource resource = entaxyResourceService.getResource(xsltLocation);
|
||||
if (!resource.exists()) {
|
||||
log.warn("XSL [{}] not found, was defined in [{}]", xsltLocation, properties);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
Processor processor = new Processor(false);
|
||||
XsltCompiler compiler = processor.newXsltCompiler();
|
||||
XsltExecutable stylesheet;
|
||||
StringWriter result = new StringWriter();
|
||||
try {
|
||||
compiler.setErrorListener(new ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void warning(TransformerException exception) throws TransformerException {
|
||||
log.warn("SAXON COMPILER:", exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatalError(TransformerException exception) throws TransformerException {
|
||||
log.error("SAXON COMPILER:", exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(TransformerException exception) throws TransformerException {
|
||||
log.error("SAXON COMPILER:", exception);
|
||||
}
|
||||
});
|
||||
stylesheet = compiler.compile(new StreamSource(resource.getInputStream()));
|
||||
Serializer out = processor.newSerializer(result);
|
||||
out.setOutputProperty(Serializer.Property.METHOD, "xml");
|
||||
out.setOutputProperty(Serializer.Property.INDENT, "yes");
|
||||
XsltTransformer transformer = stylesheet.load();
|
||||
Source xml = new StreamSource(new StringReader(value.toString()));
|
||||
transformer.setSource(xml);
|
||||
transformer.setDestination(out);
|
||||
if (properties.containsKey(PROP_PARAMETERS)) {
|
||||
Object obj = properties.get(PROP_PARAMETERS);
|
||||
if (obj instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>)obj;
|
||||
for (Map.Entry<String, Object> entry: map.entrySet()) {
|
||||
transformer.setParameter(
|
||||
new QName(entry.getKey())
|
||||
, new XdmAtomicValue(entry.getValue().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
transformer.transform();
|
||||
} catch (SaxonApiException e) {
|
||||
log.error("Error transforming [" + value.toString() + "] with [" + xsltLocation + "]", e);
|
||||
return value;
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"factory": {
|
||||
"id": "entaxy-resource",
|
||||
"type": "entaxy.resource"
|
||||
},
|
||||
"entaxy.resource": {},
|
||||
"outputs": {
|
||||
"init": {
|
||||
"isDefault": true,
|
||||
"generator": "resource-wrap"
|
||||
},
|
||||
"ref": {
|
||||
"generator": "resource-wrap",
|
||||
"scopes": ["private", "public"]
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.shell;
|
||||
|
||||
import org.apache.karaf.shell.api.action.Command;
|
||||
import org.apache.karaf.shell.api.action.lifecycle.Service;
|
||||
|
||||
@Service
|
||||
@Command(scope = EntaxyProducerServiceSupport.SCOPE, name = "factory-configuration")
|
||||
public class FactoryConfiguration extends FactoryAwareCommand {
|
||||
|
||||
@Override
|
||||
protected Object doExecute() throws Exception {
|
||||
|
||||
// OUTPUT TO SHELL
|
||||
System.out.println(entaxyFactory.getJsonConfiguration());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.shell;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.karaf.shell.api.action.Action;
|
||||
import org.apache.karaf.shell.api.action.Command;
|
||||
import org.apache.karaf.shell.api.action.lifecycle.Reference;
|
||||
import org.apache.karaf.shell.api.action.lifecycle.Service;
|
||||
import org.apache.karaf.shell.support.table.ShellTable;
|
||||
import ru.entaxy.platform.base.objects.factory.tracker.TrackedFactoryManager;
|
||||
import ru.entaxy.platform.base.objects.factory.tracker.TrackedFactoryManager.TrackedManagedFactory;
|
||||
|
||||
@Service
|
||||
@Command(scope = EntaxyProducerServiceSupport.SCOPE, name = "factory-manager-status")
|
||||
public class FactoryManagerStatus implements Action {
|
||||
|
||||
@Reference
|
||||
TrackedFactoryManager factoryManager;
|
||||
|
||||
@Override
|
||||
public Object execute() throws Exception {
|
||||
|
||||
ShellTable table = new ShellTable();
|
||||
table.column("ID");
|
||||
table.column("Active");
|
||||
table.column("Consistent");
|
||||
table.column("Up2date");
|
||||
table.column("Parent");
|
||||
table.column("Requires");
|
||||
|
||||
for (TrackedManagedFactory tmf: factoryManager.getManagedFactories()) {
|
||||
final List<String> waiting = tmf.waitingFor;
|
||||
table.addRow().addContent(
|
||||
tmf.factoryId
|
||||
, tmf.isActive?"*":""
|
||||
, tmf.isConsistent()?"*":""
|
||||
, tmf.isUpToDate?"*":""
|
||||
, decorate(tmf.parent, waiting)
|
||||
, tmf.requirements.stream().map(s -> decorate(s, waiting))
|
||||
.collect(Collectors.joining(","))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// OUTPUT TO SHELL
|
||||
table.print(System.out);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String decorate(String test, List<String> values) {
|
||||
if (values.contains(test))
|
||||
return "*" + test;
|
||||
return test;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-producing-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.producer.shell;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.karaf.shell.api.action.Command;
|
||||
import org.apache.karaf.shell.api.action.lifecycle.Service;
|
||||
import org.apache.karaf.shell.support.table.ShellTable;
|
||||
|
||||
@Service
|
||||
@Command(scope = EntaxyProducerServiceSupport.SCOPE, name = "factory-type-info")
|
||||
public class FactoryTypeInfo extends FactoryAwareCommand {
|
||||
|
||||
@Override
|
||||
protected Object doExecute() throws Exception {
|
||||
|
||||
ShellTable table = new ShellTable();
|
||||
table.column("Name");
|
||||
table.column("Value");
|
||||
|
||||
Map<String, Object> typeInfo = entaxyFactory.getTypeInfo();
|
||||
|
||||
for (Entry<String, Object> entry: typeInfo.entrySet()) {
|
||||
table.addRow().addContent(
|
||||
entry.getKey(),
|
||||
entry.getValue()==null?"":entry.getValue().toString()
|
||||
);
|
||||
}
|
||||
|
||||
table.print(System.out);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user