Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,41 @@
package step.core.collections;

import step.automation.packages.yaml.AutomationPackageYamlFragmentManager;
import step.core.accessors.AbstractOrganizableObject;
import step.core.collections.inmemory.InMemoryCollection;
import step.core.plans.Plan;
import step.plans.parser.yaml.YamlPlan;
import step.core.yaml.PatchableYamlModel;

public class AutomationPackagePlanCollection extends InMemoryCollection<Plan> implements Collection<Plan> {
public class AutomationPackageCollection<BO extends AbstractOrganizableObject, YO extends PatchableYamlModel> extends InMemoryCollection<BO> implements Collection<BO> {


private final AutomationPackageYamlFragmentManager fragmentManager;

public AutomationPackagePlanCollection(AutomationPackageYamlFragmentManager fragmentManager) {
super(false, YamlPlan.PLANS_ENTITY_NAME);
public AutomationPackageCollection(AutomationPackageYamlFragmentManager fragmentManager, Class<BO> boClass) {
super(false);
this.fragmentManager = fragmentManager;
initialzeRecordsFromFragments(fragmentManager);
initialzeRecordsFromFragments(boClass, fragmentManager);
}

private void initialzeRecordsFromFragments(AutomationPackageYamlFragmentManager fragmentManager) {
private void initialzeRecordsFromFragments(Class<BO> boClass, AutomationPackageYamlFragmentManager fragmentManager) {
// initialization into the collection memory. Calls super save to avoid calling fragmentManager.savePlan
fragmentManager.getBusinessObjects(Plan.class).forEach(super::save);
fragmentManager.getBusinessObjects(boClass).forEach(super::save);
}

@Override
public Plan save(Plan p) {
return fragmentManager.savePlan(super.save(p));
public BO save(BO p) {
return fragmentManager.save(super.save(p));
}

@Override
public void save(Iterable<Plan> iterable) {
for (Plan p : iterable) {
save(p);
public void save(Iterable<BO> iterable) {
for (BO object : iterable) {
save(object);
}
}

@Override
public void remove(Filter filter) {
find(filter, null, null, null, 0).forEach(fragmentManager::removePlan);
find(filter, null, null, null, 0).forEach(fragmentManager::remove);
super.remove(filter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
******************************************************************************/
package step.core.collections;

import step.automation.packages.model.YamlAutomationPackageKeyword;
import step.automation.packages.yaml.AutomationPackageYamlFragmentManager;
import step.core.collections.inmemory.InMemoryCollectionFactory;
import step.core.plans.Plan;
import step.functions.Function;
import step.parameter.Parameter;
import step.parameter.automation.AutomationPackageParameter;
import step.plans.parser.yaml.YamlPlan;

import java.io.IOException;
import java.util.Map;
Expand All @@ -45,11 +48,11 @@ public AutomationPackageCollectionFactory(Properties properties, AutomationPacka
public <T> Collection<T> getCollection(String name, Class<T> entityClass) {
return (Collection<T>) collectionsByName.computeIfAbsent(name, (_name) -> {
if (Plan.class.isAssignableFrom(entityClass)) {
return new AutomationPackagePlanCollection(fragmentManager);
return new AutomationPackageCollection<Plan, YamlPlan>(fragmentManager, Plan.class);
} else if (Parameter.class.isAssignableFrom(entityClass)) {
return new AutomationPackageParameterCollection(fragmentManager);
return new AutomationPackageCollection<Parameter, AutomationPackageParameter>(fragmentManager, Parameter.class);
} else if (Function.class.isAssignableFrom(entityClass)) {
return new AutomationPackageFunctionCollection(fragmentManager);
return new AutomationPackageCollection<Function, YamlAutomationPackageKeyword>(fragmentManager, Function.class);
}
return baseFactory.getCollection(name, entityClass);
});
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ public void testAddPlanToNewFragmentAndRenameAndRemove() throws IOException {

@Test
public void testAddTwoPlansToNewFragmentAndRemoveOne() throws IOException {

Sequence sequence = new Sequence();
Echo echo = new Echo();
echo.setText(new DynamicValue<>("Hello World"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import step.automation.packages.yaml.AutomationPackageYamlFragmentManager;
import step.automation.packages.yaml.model.AutomationPackageDescriptorYaml;
import step.automation.packages.yaml.model.AutomationPackageFragmentYaml;
import step.commons.activation.Expression;
import step.core.plans.Plan;
import step.core.yaml.deserialization.PatchableYamlList;
import step.core.yaml.deserialization.PatchableYamlPrimitive;
Expand Down Expand Up @@ -192,7 +193,9 @@ public AutomationPackageYamlFragmentManager getAutomationPackageYamlFragmentMana
AutomationPackageContent content = newContentInstance();
Set<AutomationPackageFragmentYaml> fragments = new HashSet<>();
fillAutomationPackageWithImportedFragments(content, descriptor, archive, fragments);
StagingAutomationPackageContext stagingContext = new StagingAutomationPackageContext(null, AutomationPackageOperationMode.LOCAL, new LocalResourceManagerImpl(descriptorPath.getParent().toFile()), archive, content, null, null, new HashMap<>());
AutomationPackage automationPackage = new AutomationPackage();
automationPackage.setStatus(AutomationPackageStatus.EDIT);
StagingAutomationPackageContext stagingContext = new StagingAutomationPackageContext(automationPackage, AutomationPackageOperationMode.LOCAL, new LocalResourceManagerImpl(descriptorPath.getParent().toFile()), archive, content, null, null, new HashMap<>());
return new AutomationPackageYamlFragmentManager(archive.getResourcePathMatchingResolver(), descriptor, fragments, getOrCreateDescriptorReader(), stagingContext);
} catch (FileSystemNotFoundException | URISyntaxException e) {
throw new AutomationPackageReadingException("Failed to read automation package for editing. The most likely cause is that you were trying to load " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@

public class AutomationPackageDescriptorReader {

protected static final Logger log = LoggerFactory.getLogger(AutomationPackageDescriptorReader.class);
private static final Logger log = LoggerFactory.getLogger(AutomationPackageDescriptorReader.class);

protected final ObjectMapper yamlObjectMapper;
private final ObjectMapper yamlObjectMapper;

protected final YamlPlanReader planReader;
private final YamlPlanReader planReader;

private final AutomationPackageSerializationRegistry serializationRegistry;

protected String jsonSchema;
private String jsonSchema;

public AutomationPackageDescriptorReader(String jsonSchemaPath, AutomationPackageSerializationRegistry serializationRegistry) {
this.serializationRegistry = serializationRegistry;
Expand Down
Loading