Skip to content

Commit

Permalink
Add draft for new find fix paths modul #347
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i authored and TobiasNx committed May 7, 2024
2 parents 88eb9dd + 8a50e98 commit b8fc5c9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -24,6 +24,10 @@ Run the tests (in `metafix/src/test/java`) and checks (`.editorconfig`, `config/

`./gradlew clean check`

To execute a Fix (embedded in a Flux) via CLI:

`./gradlew :metafix-runner:run --args="$PWD/path/to.flux"`

(To import the projects in Eclipse, choose `File > Import > Existing Gradle Project` and select the `metafacture-fix` directory.)

## Usage
Expand Down
63 changes: 63 additions & 0 deletions metafix/src/main/java/org/metafacture/metafix/FindFixPaths.java
@@ -0,0 +1,63 @@
/*
* Copyright 2024 Tobias Bülte, hbz
*
* 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.
*/

package org.metafacture.metafix;

import org.metafacture.formatting.ObjectTemplate;
import org.metafacture.framework.FluxCommand;
import org.metafacture.framework.StreamReceiver;
import org.metafacture.framework.annotations.Description;
import org.metafacture.framework.annotations.In;
import org.metafacture.framework.annotations.Out;
import org.metafacture.framework.MetafactureException;
import org.metafacture.framework.ObjectReceiver;
import org.metafacture.framework.helpers.DefaultStreamPipe;
import org.metafacture.mangling.StreamFlattener;
import org.metafacture.triples.StreamToTriples;
import org.metafacture.triples.TripleFilter;

import java.io.IOException;

/**
* Provide a user-friendly way to finds all paths that have values that match
* the given pattern.
*
* @author Tobias Bülte
*/
@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.")
@In(StreamReceiver.class)
@Out(String.class)
@FluxCommand("find-fix-paths")

public class FindFixPaths extends DefaultStreamPipe<ObjectReceiver<String>> {
public FindFixPaths(final String objectPattern) {
final Metafix fix;
try {
fix = new Metafix("nothing()");
fix.setRepeatedFieldsToEntities(true);
} catch (final IOException e) {
throw new MetafactureException(e);
}
final TripleFilter tripleFilter = new TripleFilter();
tripleFilter.setObjectPattern(objectPattern);
fix
.setReceiver(new StreamFlattener())
.setReceiver(new StreamToTriples())
.setReceiver(tripleFilter)
.setReceiver(new ObjectTemplate<>("${p}\t ${o}"))
.setReceiver(getReceiver());
}
}
1 change: 1 addition & 0 deletions metafix/src/main/resources/flux-commands.properties
Expand Up @@ -15,3 +15,4 @@
fix org.metafacture.metafix.Metafix
list-fix-paths org.metafacture.metafix.ListFixPaths
list-fix-values org.metafacture.metafix.ListFixValues
find-fix-paths org.metafacture.metafix.FindFixPaths

0 comments on commit b8fc5c9

Please sign in to comment.