forked from D-Net/dnet-hadoop
mergeUtils set the result identifier when enforcing the result type
This commit is contained in:
parent
9e8849b753
commit
b95672b420
|
@ -16,8 +16,6 @@ import java.util.function.Function;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup;
|
||||
import eu.dnetlib.dhp.schema.common.EntityType;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
@ -25,8 +23,10 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
import com.github.sisyphsu.dateparser.DateParserUtils;
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup;
|
||||
import eu.dnetlib.dhp.oa.merge.AuthorMerger;
|
||||
import eu.dnetlib.dhp.schema.common.AccessRightComparator;
|
||||
import eu.dnetlib.dhp.schema.common.EntityType;
|
||||
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
||||
import eu.dnetlib.dhp.schema.common.ModelSupport;
|
||||
import eu.dnetlib.dhp.schema.oaf.*;
|
||||
|
@ -74,22 +74,29 @@ public class MergeUtils {
|
|||
if (!vocs.vocabularyExists(ModelConstants.DNET_RESULT_TYPOLOGIES)) {
|
||||
return (T) mergedResult;
|
||||
} else {
|
||||
final Qualifier expectedResultType = Optional
|
||||
.ofNullable(vocs.lookupTermBySynonym(ModelConstants.DNET_RESULT_TYPOLOGIES, i.getInstancetype().getClassid()))
|
||||
.orElse(OafMapperUtils.unknown(ModelConstants.DNET_RESULT_TYPOLOGIES, ModelConstants.DNET_RESULT_TYPOLOGIES));
|
||||
final String expectedResultType = Optional
|
||||
.ofNullable(
|
||||
vocs
|
||||
.lookupTermBySynonym(
|
||||
ModelConstants.DNET_RESULT_TYPOLOGIES, i.getInstancetype().getClassid()))
|
||||
.orElse(ModelConstants.ORP_DEFAULT_RESULTTYPE)
|
||||
.getClassid();
|
||||
|
||||
// there is a clash among the result types
|
||||
if (!expectedResultType.getClassid().equals(mergedResult.getResulttype().getClassid())) {
|
||||
if (!expectedResultType.equals(mergedResult.getResulttype().getClassid())) {
|
||||
|
||||
Result result = (Result) Optional
|
||||
.ofNullable(ModelSupport.oafTypes.get(expectedResultType))
|
||||
.map(r -> {
|
||||
try {
|
||||
String resulttype = expectedResultType.getClassid();
|
||||
if (EntityType.otherresearchproduct.toString().equals(resulttype)) {
|
||||
resulttype = "other";
|
||||
}
|
||||
Result result = (Result) ModelSupport.oafTypes.get(resulttype).newInstance();
|
||||
return (T) mergeResultFields(result, mergedResult);
|
||||
return r.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
})
|
||||
.orElse(new OtherResearchProduct());
|
||||
result.setId(mergedResult.getId());
|
||||
return (T) mergeResultFields(result, mergedResult);
|
||||
} else {
|
||||
return (T) mergedResult;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue