Skip to content

Commit 3d7b16a

Browse files
committed
Initial setup for a flux command to list available fix paths
See https://gitlab.com/oersi/oersi-etl/-/issues/238
1 parent 847bc0e commit 3d7b16a

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed

metafix/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ dependencies {
3636
implementation "org.metafacture:metafacture-io:${versions.metafacture}"
3737
implementation "org.metafacture:metafacture-javaintegration:${versions.metafacture}"
3838
implementation "org.metafacture:metafacture-mangling:${versions.metafacture}"
39+
implementation "org.metafacture:metafacture-formatting:${versions.metafacture}"
40+
implementation "org.metafacture:metafacture-triples:${versions.metafacture}"
3941
implementation "org.metafacture:metamorph:${versions.metafacture}"
4042

4143
testImplementation "nl.jqno.equalsverifier:equalsverifier:${versions.equalsverifier}"
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright 2023 Fabian Steeg, 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.ObjectReceiver;
21+
import org.metafacture.framework.helpers.DefaultStreamPipe;
22+
import org.metafacture.framework.objects.Triple;
23+
import org.metafacture.mangling.StreamFlattener;
24+
import org.metafacture.triples.AbstractTripleSort.Compare;
25+
import org.metafacture.triples.StreamToTriples;
26+
import org.metafacture.triples.TripleCount;
27+
28+
import java.io.FileNotFoundException;
29+
30+
/**
31+
* Provide a user-friendly way to list all paths available for processing in fix.
32+
*
33+
* @author Fabian Steeg
34+
*/
35+
public class MetafixListPaths extends DefaultStreamPipe<ObjectReceiver<String>> {
36+
37+
private Metafix fix;
38+
39+
public MetafixListPaths() {
40+
try {
41+
fix = new Metafix("nothing()");
42+
fix.setRepeatedFieldsToEntities(true);
43+
fix.setEntityMemberName("*");
44+
}
45+
catch (final FileNotFoundException e) {
46+
e.printStackTrace();
47+
}
48+
}
49+
50+
@Override
51+
protected void onSetReceiver() {
52+
final TripleCount tripleCount = new TripleCount();
53+
tripleCount.setCountBy(Compare.PREDICATE);
54+
fix
55+
.setReceiver(new StreamFlattener())
56+
.setReceiver(new StreamToTriples())
57+
.setReceiver(tripleCount)
58+
.setReceiver(new ObjectTemplate<Triple>("${s}\t ${o}"))
59+
.setReceiver(getReceiver());
60+
}
61+
62+
@Override
63+
public void startRecord(final String identifier) {
64+
fix.startRecord(identifier);
65+
}
66+
67+
@Override
68+
public void endRecord() {
69+
fix.endRecord();
70+
}
71+
72+
@Override
73+
public void startEntity(final String name) {
74+
fix.startEntity(name);
75+
}
76+
77+
@Override
78+
public void endEntity() {
79+
fix.endEntity();
80+
}
81+
82+
@Override
83+
public void literal(final String name, final String value) {
84+
fix.literal(name, value);
85+
}
86+
87+
@Override
88+
protected void onCloseStream() {
89+
fix.closeStream();
90+
}
91+
92+
@Override
93+
protected void onResetStream() {
94+
fix.resetStream();
95+
}
96+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
# limitations under the License.
1414
#
1515
fix org.metafacture.metafix.Metafix
16+
fix-list-paths org.metafacture.metafix.MetafixListPaths
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2023 Fabian Steeg, 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.framework.ObjectReceiver;
20+
21+
import org.junit.jupiter.api.Test;
22+
import org.mockito.Mock;
23+
import org.mockito.Mockito;
24+
import org.mockito.MockitoAnnotations;
25+
import org.mockito.exceptions.base.MockitoAssertionError;
26+
27+
/**
28+
* Tests for class {@link MetafixListPaths}.
29+
*
30+
* @author Fabian Steeg
31+
*
32+
*/
33+
public final class MetafixListPathsTest {
34+
35+
private MetafixListPaths lister;
36+
37+
@Mock
38+
private ObjectReceiver<String> receiver;
39+
40+
public MetafixListPathsTest() {
41+
MockitoAnnotations.initMocks(this);
42+
lister = new MetafixListPaths();
43+
lister.setReceiver(receiver);
44+
}
45+
46+
@Test
47+
public void testShouldListPaths() {
48+
lister.startRecord("");
49+
lister.literal("a", "A");
50+
lister.literal("a", "B");
51+
lister.literal("a", "C");
52+
lister.endRecord();
53+
lister.closeStream();
54+
try {
55+
Mockito.verify(receiver).process("a.*\t 3");
56+
}
57+
catch (final MockitoAssertionError e) {
58+
System.out.println(Mockito.mockingDetails(receiver).printInvocations());
59+
throw e;
60+
}
61+
}
62+
63+
}

0 commit comments

Comments
 (0)