-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(#3266): Add API to programmatically create pipelines * Fix checkstyle * feat(#3280): Add support for pipeline templates * Fix validation * Remove obsolete stylesheet * Fix dependency * Add default template to setup * feat(#3292): Show adapter and pipeline configuration in UI (#3293) * feat(#3292): Add code tab to adapter view * Show pipeline code in UI * Add header * Fix checkstyle * Fix checkstyle * Fix template visitor * Remove empty css class
- Loading branch information
1 parent
59773aa
commit 359b863
Showing
94 changed files
with
2,435 additions
and
1,364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
.../org/apache/streampipes/connect/management/compact/generator/CompactAdapterGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
* | ||
*/ | ||
|
||
package org.apache.streampipes.connect.management.compact.generator; | ||
|
||
import org.apache.streampipes.connect.shared.preprocessing.convert.ToOriginalSchemaConverter; | ||
import org.apache.streampipes.manager.template.CompactConfigGenerator; | ||
import org.apache.streampipes.model.connect.adapter.AdapterDescription; | ||
import org.apache.streampipes.model.connect.adapter.compact.CompactEventProperty; | ||
import org.apache.streampipes.model.connect.adapter.compact.CreateOptions; | ||
import org.apache.streampipes.model.connect.adapter.compact.EnrichmentConfig; | ||
import org.apache.streampipes.model.connect.adapter.compact.TransformationConfig; | ||
import org.apache.streampipes.model.connect.rules.TransformationRuleDescription; | ||
import org.apache.streampipes.model.connect.rules.schema.RenameRuleDescription; | ||
import org.apache.streampipes.model.connect.rules.value.AddTimestampRuleDescription; | ||
import org.apache.streampipes.model.connect.rules.value.UnitTransformRuleDescription; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CompactAdapterGenerator { | ||
|
||
private final AdapterDescription adapterDescription; | ||
|
||
public CompactAdapterGenerator(AdapterDescription adapterDescription) { | ||
this.adapterDescription = adapterDescription; | ||
} | ||
|
||
public List<Map<String, Object>> getConfig() { | ||
var configs = new ArrayList<Map<String, Object>>(); | ||
adapterDescription.getConfig().forEach(c -> { | ||
configs.add(new CompactConfigGenerator(c).toTemplateValue()); | ||
}); | ||
return configs; | ||
} | ||
|
||
public Map<String, CompactEventProperty> getSchema() { | ||
var map = new HashMap<String, CompactEventProperty>(); | ||
var originalProperties = new ToOriginalSchemaConverter( | ||
adapterDescription.getEventSchema().getEventProperties() | ||
).getTransformedProperties(); | ||
originalProperties | ||
.forEach(ep -> map.put(ep.getRuntimeName(), new CompactEventProperty( | ||
ep.getLabel(), | ||
ep.getDescription(), | ||
ep.getPropertyScope(), | ||
ep.getSemanticType() | ||
))); | ||
return map; | ||
} | ||
|
||
public EnrichmentConfig getEnrichmentConfig() { | ||
if (hasTimestampEnrichmentRule()) { | ||
return new EnrichmentConfig(AdapterEnrichmentRuleGenerator.TIMESTAMP_FIELD); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public TransformationConfig getTransformationConfig() { | ||
var renameRules = new HashMap<String, String>(); | ||
var unitTransformRules = new HashMap<String, String>(); | ||
if (hasTransformationRule()) { | ||
if (hasRule(RenameRuleDescription.class)) { | ||
var rules = getRules(RenameRuleDescription.class); | ||
rules.forEach(rule -> { | ||
renameRules.put(rule.getOldRuntimeKey(), rule.getNewRuntimeKey()); | ||
}); | ||
} else if (hasRule(UnitTransformRuleDescription.class)) { | ||
var rules = getRules(UnitTransformRuleDescription.class); | ||
rules.forEach(rule -> { | ||
unitTransformRules.put(rule.getRuntimeKey(), rule.getToUnitRessourceURL()); | ||
}); | ||
} | ||
} | ||
return new TransformationConfig(renameRules, unitTransformRules); | ||
} | ||
|
||
public CreateOptions getCreateOptions() { | ||
return new CreateOptions( | ||
true, | ||
true | ||
); | ||
} | ||
|
||
private boolean hasTimestampEnrichmentRule() { | ||
return hasRule(AddTimestampRuleDescription.class); | ||
} | ||
|
||
private boolean hasTransformationRule() { | ||
return adapterDescription.getRules().stream() | ||
.anyMatch(r -> hasRule(RenameRuleDescription.class) || hasRule(UnitTransformRuleDescription.class)); | ||
} | ||
|
||
private boolean hasRule(Class<? extends TransformationRuleDescription> rule) { | ||
return adapterDescription.getRules().stream().anyMatch(r -> r.getClass().equals(rule)); | ||
} | ||
|
||
private <T extends TransformationRuleDescription> List<T> getRules(Class<T> rule) { | ||
return adapterDescription.getRules() | ||
.stream() | ||
.filter(rule::isInstance) | ||
.map(rule::cast) | ||
.toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.