Skip to content

Commit b8fc5c9

Browse files
dr0iTobiasNx
authored andcommitted
Add draft for new find fix paths modul #347
2 parents 88eb9dd + 8a50e98 commit b8fc5c9

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Run the tests (in `metafix/src/test/java`) and checks (`.editorconfig`, `config/
2424

2525
`./gradlew clean check`
2626

27+
To execute a Fix (embedded in a Flux) via CLI:
28+
29+
`./gradlew :metafix-runner:run --args="$PWD/path/to.flux"`
30+
2731
(To import the projects in Eclipse, choose `File > Import > Existing Gradle Project` and select the `metafacture-fix` directory.)
2832

2933
## Usage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2024 Tobias Bülte, hbz
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix;
18+
19+
import org.metafacture.formatting.ObjectTemplate;
20+
import org.metafacture.framework.FluxCommand;
21+
import org.metafacture.framework.StreamReceiver;
22+
import org.metafacture.framework.annotations.Description;
23+
import org.metafacture.framework.annotations.In;
24+
import org.metafacture.framework.annotations.Out;
25+
import org.metafacture.framework.MetafactureException;
26+
import org.metafacture.framework.ObjectReceiver;
27+
import org.metafacture.framework.helpers.DefaultStreamPipe;
28+
import org.metafacture.mangling.StreamFlattener;
29+
import org.metafacture.triples.StreamToTriples;
30+
import org.metafacture.triples.TripleFilter;
31+
32+
import java.io.IOException;
33+
34+
/**
35+
* Provide a user-friendly way to finds all paths that have values that match
36+
* the given pattern.
37+
*
38+
* @author Tobias Bülte
39+
*/
40+
@Description("Finds all paths that have values that match the given pattern. Allows for regex. These paths can be used in a Fix to address fields.")
41+
@In(StreamReceiver.class)
42+
@Out(String.class)
43+
@FluxCommand("find-fix-paths")
44+
45+
public class FindFixPaths extends DefaultStreamPipe<ObjectReceiver<String>> {
46+
public FindFixPaths(final String objectPattern) {
47+
final Metafix fix;
48+
try {
49+
fix = new Metafix("nothing()");
50+
fix.setRepeatedFieldsToEntities(true);
51+
} catch (final IOException e) {
52+
throw new MetafactureException(e);
53+
}
54+
final TripleFilter tripleFilter = new TripleFilter();
55+
tripleFilter.setObjectPattern(objectPattern);
56+
fix
57+
.setReceiver(new StreamFlattener())
58+
.setReceiver(new StreamToTriples())
59+
.setReceiver(tripleFilter)
60+
.setReceiver(new ObjectTemplate<>("${p}\t ${o}"))
61+
.setReceiver(getReceiver());
62+
}
63+
}

metafix/src/main/resources/flux-commands.properties

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
fix org.metafacture.metafix.Metafix
1616
list-fix-paths org.metafacture.metafix.ListFixPaths
1717
list-fix-values org.metafacture.metafix.ListFixValues
18+
find-fix-paths org.metafacture.metafix.FindFixPaths

0 commit comments

Comments
 (0)