2021-12-14 11:12:17 +01:00
|
|
|
|
2021-12-22 16:44:44 +01:00
|
|
|
package eu.dnetlib.dhp.actionmanager;
|
2021-12-14 11:12:17 +01:00
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
import org.apache.spark.api.java.function.MapFunction;
|
|
|
|
import org.apache.spark.sql.Dataset;
|
|
|
|
import org.apache.spark.sql.Encoders;
|
|
|
|
import org.apache.spark.sql.SparkSession;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
2021-12-22 21:40:35 +01:00
|
|
|
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
|
|
|
import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
|
|
|
|
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils;
|
2021-12-14 11:12:17 +01:00
|
|
|
|
|
|
|
public class Constants {
|
|
|
|
|
|
|
|
public static final String DOI = "doi";
|
2022-01-12 16:53:47 +01:00
|
|
|
public static final String DOI_CLASSNAME = "Digital Object Identifier";
|
2021-12-14 11:12:17 +01:00
|
|
|
|
2022-01-03 15:23:06 +01:00
|
|
|
public static final String DEFAULT_DELIMITER = ",";
|
2021-12-23 13:24:28 +01:00
|
|
|
|
2021-12-14 11:12:17 +01:00
|
|
|
public static final String UPDATE_DATA_INFO_TYPE = "update";
|
|
|
|
public static final String UPDATE_SUBJECT_FOS_CLASS_ID = "subject:fos";
|
|
|
|
public static final String UPDATE_CLASS_NAME = "Inferred by OpenAIRE";
|
|
|
|
public static final String UPDATE_MEASURE_BIP_CLASS_ID = "measure:bip";
|
2021-12-23 13:24:28 +01:00
|
|
|
public static final String UPDATE_SUBJECT_SDG_CLASS_ID = "subject:sdg";
|
2022-04-20 14:02:05 +02:00
|
|
|
public static final String UPDATE_MEASURE_USAGE_COUNTS_CLASS_ID = "measure:usage_counts";
|
|
|
|
public static final String UPDATE_KEY_USAGE_COUNTS = "count";
|
2021-12-14 11:12:17 +01:00
|
|
|
|
|
|
|
public static final String FOS_CLASS_ID = "FOS";
|
|
|
|
public static final String FOS_CLASS_NAME = "Fields of Science and Technology classification";
|
|
|
|
|
2021-12-23 13:24:28 +01:00
|
|
|
public static final String SDG_CLASS_ID = "SDG";
|
|
|
|
public static final String SDG_CLASS_NAME = "Sustainable Development Goals";
|
|
|
|
|
2021-12-14 11:12:17 +01:00
|
|
|
public static final String NULL = "NULL";
|
|
|
|
|
|
|
|
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
|
|
|
|
|
|
|
private Constants() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Boolean isSparkSessionManaged(ArgumentApplicationParser parser) {
|
|
|
|
return Optional
|
|
|
|
.ofNullable(parser.get("isSparkSessionManaged"))
|
|
|
|
.map(Boolean::valueOf)
|
|
|
|
.orElse(Boolean.TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <R> Dataset<R> readPath(
|
|
|
|
SparkSession spark, String inputPath, Class<R> clazz) {
|
|
|
|
return spark
|
|
|
|
.read()
|
|
|
|
.textFile(inputPath)
|
|
|
|
.map((MapFunction<String, R>) value -> OBJECT_MAPPER.readValue(value, clazz), Encoders.bean(clazz));
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:23:06 +01:00
|
|
|
public static StructuredProperty getSubject(String sbj, String classid, String classname,
|
|
|
|
String diqualifierclassid) {
|
2021-12-22 16:44:44 +01:00
|
|
|
if (sbj.equals(NULL))
|
|
|
|
return null;
|
|
|
|
StructuredProperty sp = new StructuredProperty();
|
|
|
|
sp.setValue(sbj);
|
|
|
|
sp
|
2021-12-22 21:40:35 +01:00
|
|
|
.setQualifier(
|
|
|
|
OafMapperUtils
|
|
|
|
.qualifier(
|
|
|
|
classid,
|
|
|
|
classname,
|
|
|
|
ModelConstants.DNET_SUBJECT_TYPOLOGIES,
|
|
|
|
ModelConstants.DNET_SUBJECT_TYPOLOGIES));
|
2021-12-22 16:44:44 +01:00
|
|
|
sp
|
2021-12-22 21:40:35 +01:00
|
|
|
.setDataInfo(
|
|
|
|
OafMapperUtils
|
|
|
|
.dataInfo(
|
|
|
|
false,
|
|
|
|
UPDATE_DATA_INFO_TYPE,
|
|
|
|
true,
|
|
|
|
false,
|
2021-12-22 16:44:44 +01:00
|
|
|
OafMapperUtils
|
2021-12-22 21:40:35 +01:00
|
|
|
.qualifier(
|
2022-01-03 15:23:06 +01:00
|
|
|
diqualifierclassid,
|
2021-12-22 21:40:35 +01:00
|
|
|
UPDATE_CLASS_NAME,
|
|
|
|
ModelConstants.DNET_PROVENANCE_ACTIONS,
|
|
|
|
ModelConstants.DNET_PROVENANCE_ACTIONS),
|
|
|
|
""));
|
2021-12-22 16:44:44 +01:00
|
|
|
|
|
|
|
return sp;
|
|
|
|
|
|
|
|
}
|
2021-12-14 11:12:17 +01:00
|
|
|
}
|