Oaf merge and get strategy added

This commit is contained in:
Przemysław Jacewicz 2020-03-11 16:58:17 +01:00
parent f7454a9ed8
commit e6e214dab5
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package eu.dnetlib.dhp.actionmanager;
import eu.dnetlib.dhp.schema.oaf.Oaf;
import eu.dnetlib.dhp.schema.oaf.OafEntity;
import eu.dnetlib.dhp.schema.oaf.Relation;
import java.util.function.BiFunction;
public class OafMergeAndGet {
public enum Strategy {
MERGE_FROM_AND_GET, SELECT_NEWER_AND_GET
}
public static <T extends Oaf> SerializableSupplier<BiFunction<T, T, T>> functionFor(Strategy strategy) {
switch (strategy) {
case MERGE_FROM_AND_GET:
return () -> (x, y) -> {
if (x instanceof Relation) {
((Relation) x).mergeFrom((Relation) y);
return x;
}
((OafEntity) x).mergeFrom((OafEntity) y);
return x;
};
case SELECT_NEWER_AND_GET:
return () -> (x, y) -> {
if (x.getLastupdatetimestamp() > y.getLastupdatetimestamp()) {
return x;
}
return y;
};
}
throw new RuntimeException();
}
}