Skip to content

Commit 1e58da1

Browse files
committed
feature(template): prov storage compatible cpm documents
1 parent 95bcb95 commit 1e58da1

25 files changed

+1778
-1152
lines changed

cpm-template/src/test/java/cz/muni/fi/cpm/template/deserialization/embrc/CpmEmbrcTest.java

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,32 @@
1010
import cz.muni.fi.cpm.template.deserialization.embrc.transform.cpm.*;
1111
import cz.muni.fi.cpm.template.deserialization.embrc.transform.jsonld.EmbrcTransformer;
1212
import cz.muni.fi.cpm.template.deserialization.embrc.transform.jsonld.ProvContextManager;
13+
import cz.muni.fi.cpm.template.deserialization.embrc.transform.storage.EmbrcProvStorageTransformer;
1314
import cz.muni.fi.cpm.template.util.GraphvizChecker;
1415
import cz.muni.fi.cpm.vanilla.CpmProvFactory;
1516
import org.junit.jupiter.api.MethodOrderer;
1617
import org.junit.jupiter.api.Order;
1718
import org.junit.jupiter.api.TestMethodOrder;
1819
import org.junit.jupiter.params.ParameterizedTest;
1920
import org.junit.jupiter.params.provider.MethodSource;
21+
import org.junit.jupiter.params.provider.ValueSource;
2022
import org.openprovenance.prov.interop.InteropFramework;
2123
import org.openprovenance.prov.model.Document;
2224
import org.openprovenance.prov.model.ProvFactory;
2325
import org.openprovenance.prov.model.interop.Formats;
2426

25-
import java.io.File;
26-
import java.io.FileInputStream;
27-
import java.io.IOException;
28-
import java.io.InputStream;
27+
import java.io.*;
2928
import java.lang.reflect.InvocationTargetException;
3029
import java.util.stream.Stream;
3130

3231
import static cz.muni.fi.cpm.template.constants.PathConstants.TEST_RESOURCES;
32+
import static cz.muni.fi.cpm.template.deserialization.embrc.transform.storage.EmbrcProvStorageTransformer.V0_SUFFIX;
33+
import static cz.muni.fi.cpm.template.deserialization.embrc.transform.storage.EmbrcProvStorageTransformer.V1_SUFFIX;
3334
import static org.junit.jupiter.api.Assertions.assertEquals;
3435

3536
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
3637
public class CpmEmbrcTest {
37-
private static final String EMBRC_FOLDER = "embrc" + File.separator;
38+
public static final String EMBRC_FOLDER = "embrc" + File.separator;
3839

3940
private final ProvFactory pF;
4041
private final ICpmProvFactory cPF;
@@ -46,27 +47,19 @@ public CpmEmbrcTest() {
4647
cF = new CpmMergedFactory(pF);
4748
}
4849

49-
private static Stream<Object[]> dataSetProvider() {
50-
return Stream.of(
51-
new Object[]{1},
52-
new Object[]{2},
53-
new Object[]{3},
54-
new Object[]{4}
55-
);
56-
}
57-
50+
// 5 in TI for dataset 2, because sender and receiver agents are merged
5851
private static Stream<Object[]> documentProvider() {
5952
return Stream.of(
60-
new Object[]{Dataset1Transformer.class, 1, 7, 35, 2},
61-
new Object[]{Dataset2Transformer.class, 2, 4, 11, 2},
62-
new Object[]{Dataset3Transformer.class, 3, 4, 7, 2},
63-
new Object[]{Dataset4Transformer.class, 4, 3, 42, 2}
53+
new Object[]{Dataset1Transformer.class, 1, 9, 35, 2},
54+
new Object[]{Dataset2Transformer.class, 2, 5, 11, 2},
55+
new Object[]{Dataset3Transformer.class, 3, 5, 7, 2},
56+
new Object[]{Dataset4Transformer.class, 4, 4, 42, 2}
6457
);
6558
}
6659

6760
@Order(0)
6861
@ParameterizedTest
69-
@MethodSource("dataSetProvider")
62+
@ValueSource(ints = {1, 2, 3, 4})
7063
public void transformEmbrcToProvJsonLD(int datasetNum) throws IOException, JsonLdError {
7164
String datasetFolder = "dataset" + datasetNum + File.separator;
7265
String inputFile = TEST_RESOURCES + EMBRC_FOLDER + datasetFolder + "Dataset" + datasetNum + "_ProvenanceMetadata.jsonld";
@@ -122,4 +115,34 @@ public void toDocument_withEmbrcDataset_serialisesSuccessfully(Class<DatasetTran
122115
throw new RuntimeException(e);
123116
}
124117
}
118+
119+
@Order(3)
120+
@ParameterizedTest
121+
@ValueSource(ints = {1, 2})
122+
public void transformCpmToProvStorageFormatV0(int datasetNum) throws IOException {
123+
String datasetFolder = "dataset" + datasetNum + File.separator;
124+
String filePath = TEST_RESOURCES + EMBRC_FOLDER + datasetFolder + "Dataset" + datasetNum + "_cpm";
125+
EmbrcProvStorageTransformer pST = new EmbrcProvStorageTransformer(pF);
126+
127+
try (InputStream inputStream = new FileInputStream(filePath + ".jsonld")) {
128+
ByteArrayOutputStream outputStreamV0 = pST.transformToV0(inputStream);
129+
outputStreamV0.writeTo(new FileOutputStream(filePath + "_storage_v0.json"));
130+
}
131+
}
132+
133+
@Order(4)
134+
@ParameterizedTest
135+
@ValueSource(ints = {4, 3, 2, 1})
136+
public void transformCpmToProvStorageFormatV1(int datasetNum) throws IOException {
137+
String datasetFolder = "dataset" + datasetNum + File.separator;
138+
String filePath = TEST_RESOURCES + EMBRC_FOLDER + datasetFolder + "Dataset" + datasetNum + "_cpm";
139+
EmbrcProvStorageTransformer pST = new EmbrcProvStorageTransformer(pF);
140+
141+
try (InputStream inputStream = new FileInputStream(filePath + ".jsonld")) {
142+
String suffix = datasetNum == 1 || datasetNum == 2 ? V1_SUFFIX : V0_SUFFIX;
143+
ByteArrayOutputStream outputStreamV1 = pST.transformToV1(inputStream, suffix);
144+
outputStreamV1.writeTo(new FileOutputStream(filePath + "_storage" + suffix + ".json"));
145+
146+
}
147+
}
125148
}

cpm-template/src/test/java/cz/muni/fi/cpm/template/deserialization/embrc/transform/cpm/Dataset1Transformer.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package cz.muni.fi.cpm.template.deserialization.embrc.transform.cpm;
22

33
import cz.muni.fi.cpm.model.ICpmProvFactory;
4-
import cz.muni.fi.cpm.template.schema.ForwardConnector;
5-
import cz.muni.fi.cpm.template.schema.MainActivity;
6-
import cz.muni.fi.cpm.template.schema.TraversalInformation;
4+
import cz.muni.fi.cpm.template.schema.*;
75
import org.openprovenance.prov.model.*;
86

97
import java.util.List;
@@ -44,17 +42,25 @@ protected Document createTI(IndexedDocument indexedDS) {
4442

4543
mA.setHasPart(indexedDS.getActivities().stream().map(Identifiable::getId).toList());
4644

45+
ReceiverAgent stationAg = new ReceiverAgent(newQNWithBlankNS(NICE_MARINE_STATION));
46+
47+
ReceiverAgent seqAg = new ReceiverAgent(newQNWithBlankNS(SEQUENCING_IS_US_HQ));
48+
49+
ti.setReceiverAgents(List.of(stationAg, seqAg));
50+
4751
ForwardConnector fcR1 = new ForwardConnector(newQNWithBlankNS(STORED_SAMPLE_CON_R1));
4852

4953
ForwardConnector fcR1Spec = new ForwardConnector(newQNWithBlankNS(STORED_SAMPLE_CON_R1 + "_Spec"));
5054
fcR1Spec.setReferencedBundleId(newQNWithBlankNS(PROCESSING + "Bundle"));
5155
fcR1Spec.setSpecializationOf(fcR1.getId());
56+
fcR1Spec.setAttributedTo(new ConnectorAttributed(stationAg.getId()));
5257

5358
ForwardConnector fcR23UM = new ForwardConnector(newQNWithBlankNS(STORED_SAMPLE_CON_R2_3UM));
5459

5560
ForwardConnector fcR23UMSpec = new ForwardConnector(newQNWithBlankNS(STORED_SAMPLE_CON_R2_3UM + "_Spec"));
5661
fcR23UMSpec.setReferencedBundleId(newQNWithBlankNS(DNA_SEQUENCING + "Bundle"));
5762
fcR23UMSpec.setSpecializationOf(fcR23UM.getId());
63+
fcR23UMSpec.setAttributedTo(new ConnectorAttributed(seqAg.getId()));
5864

5965
mA.setGenerated(List.of(fcR1.getId(), fcR23UM.getId()));
6066

@@ -64,9 +70,11 @@ protected Document createTI(IndexedDocument indexedDS) {
6470
ForwardConnector fCIdenSpec = new ForwardConnector(newQNWithBlankNS(IDENTIFIED_SPECIES_CON + "Spec"));
6571
fCIdenSpec.setReferencedBundleId(newQNWithBlankNS(SPECIES_IDENTIFICATION + "Bundle"));
6672
fCIdenSpec.setSpecializationOf(fCIden.getId());
73+
fCIdenSpec.setAttributedTo(new ConnectorAttributed(stationAg.getId()));
6774

6875
ti.getForwardConnectors().addAll(List.of(fcR1, fcR1Spec, fcR23UM, fcR23UMSpec, fCIden, fCIdenSpec));
6976

77+
7078
return mapper.map(ti);
7179
}
7280

cpm-template/src/test/java/cz/muni/fi/cpm/template/deserialization/embrc/transform/cpm/Dataset2Transformer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ protected Document createTI(IndexedDocument indexedDS) {
2727
MainActivity mA = new MainActivity(newQNWithBlankNS(PROCESSING));
2828
ti.setMainActivity(mA);
2929

30+
SenderAgent stationSenderAg = new SenderAgent(newQNWithBlankNS(NICE_MARINE_STATION));
31+
// SenderAgent stationSenderAg = new SenderAgent(newQNWithBlankNS("NiceMarineStationSender"));
32+
ti.setSenderAgents(List.of(stationSenderAg));
33+
34+
ReceiverAgent stationAg = new ReceiverAgent(newQNWithBlankNS("NiceMarineStation"));
35+
// ReceiverAgent stationAg = new ReceiverAgent(newQNWithBlankNS("NiceMarineStationReceiver"));
36+
ti.setReceiverAgents(List.of(stationAg));
37+
3038
mA.setHasPart(indexedDS.getActivities().stream().map(Identifiable::getId).toList());
3139

3240
BackwardConnector bC = new BackwardConnector(newQNWithBlankNS(STORED_SAMPLE_CON_R1));
3341
bC.setReferencedBundleId(newQNWithBlankNS(SAMPLING + "Bundle"));
42+
bC.setAttributedTo(new ConnectorAttributed(stationSenderAg.getId()));
3443
ti.setBackwardConnectors(List.of(bC));
3544

3645
mA.setUsed(List.of(new MainActivityUsed(bC.getId())));
@@ -40,6 +49,7 @@ protected Document createTI(IndexedDocument indexedDS) {
4049

4150
ForwardConnector fCSpec = new ForwardConnector(newQNWithBlankNS(PROCESSED_SAMPLE_CON + "Spec"));
4251
fCSpec.setReferencedBundleId(newQNWithBlankNS(SPECIES_IDENTIFICATION + "Bundle"));
52+
fCSpec.setAttributedTo(new ConnectorAttributed(stationAg.getId()));
4353
fCSpec.setSpecializationOf(fC.getId());
4454

4555
mA.setGenerated(List.of(fC.getId()));

cpm-template/src/test/java/cz/muni/fi/cpm/template/deserialization/embrc/transform/cpm/Dataset3Transformer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ protected Document createTI(IndexedDocument indexedDS) {
2929
MainActivity mA = new MainActivity(newQNWithBlankNS(SPECIES_IDENTIFICATION));
3030
ti.setMainActivity(mA);
3131

32+
SenderAgent stationAg = new SenderAgent(newQNWithBlankNS(NICE_MARINE_STATION));
33+
ti.setSenderAgents(List.of(stationAg));
34+
3235
mA.setHasPart(indexedDS.getActivities().stream().map(Identifiable::getId).toList());
3336

3437
BackwardConnector bC = new BackwardConnector(newQNWithBlankNS(PROCESSED_SAMPLE_CON));
38+
bC.setAttributedTo(new ConnectorAttributed(stationAg.getId()));
3539
bC.setReferencedBundleId(newQNWithBlankNS(PROCESSING + "Bundle"));
3640

3741
mA.setUsed(List.of(new MainActivityUsed(bC.getId())));
3842

3943
BackwardConnector bcStored = new BackwardConnector(newQNWithBlankNS(STORED_SAMPLE_CON_R1));
4044
bcStored.setReferencedBundleId(newQNWithBlankNS(SAMPLING + "Bundle"));
45+
bcStored.setAttributedTo(new ConnectorAttributed(stationAg.getId()));
4146
bC.setDerivedFrom(List.of(bcStored.getId()));
4247

4348
ti.setBackwardConnectors(List.of(bC, bcStored));

cpm-template/src/test/java/cz/muni/fi/cpm/template/deserialization/embrc/transform/cpm/Dataset4Transformer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ protected Document createTI(IndexedDocument indexedDS) {
3636
MainActivity mA = new MainActivity(newQNWithBlankNS(DNA_SEQUENCING));
3737
ti.setMainActivity(mA);
3838

39+
SenderAgent stationAg = new SenderAgent(newQNWithBlankNS(NICE_MARINE_STATION));
40+
ti.setSenderAgents(List.of(stationAg));
41+
3942
mA.setHasPart(indexedDS.getActivities().stream().map(Identifiable::getId).toList());
4043

4144
BackwardConnector bC = new BackwardConnector(newQNWithBlankNS(STORED_SAMPLE_CON_R2_3UM));
4245
bC.setReferencedBundleId(newQNWithBlankNS(SAMPLING + "Bundle"));
46+
bC.setAttributedTo(new ConnectorAttributed(stationAg.getId()));
4347
ti.setBackwardConnectors(List.of(bC));
4448

4549
mA.setUsed(List.of(new MainActivityUsed(bC.getId())));

cpm-template/src/test/java/cz/muni/fi/cpm/template/deserialization/embrc/transform/cpm/DatasetTransformer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ public abstract class DatasetTransformer {
1010
protected static final String BLANK_PREFIX = "_";
1111
protected static final String GEN_NS = "gen/";
1212
protected static final String GEN_PREFIX = "gen";
13+
1314
protected final ProvFactory pF;
1415
protected final ICpmProvFactory cPF;
1516
protected final ProvUtilities u;
1617
protected final ITemplateProvMapper mapper;
1718

19+
protected static final String NICE_MARINE_STATION = "NiceMarineStation";
20+
protected static final String SEQUENCING_IS_US_HQ = "SequencingIsUsHQ";
21+
1822
public DatasetTransformer(ProvFactory pF, ICpmProvFactory cPF) {
1923
this.pF = pF;
2024
this.cPF = cPF;
2125
this.u = new ProvUtilities();
22-
this.mapper = new TemplateProvMapper(cPF);
26+
this.mapper = new TemplateProvMapper(cPF, true);
2327
}
2428

2529
public Document toDocument(Document dsDoc) {

0 commit comments

Comments
 (0)