();
+ String[] tokens = StringUtils.split(wfSourceDir, File.separatorChar);
+ ArrayUtils.reverse(tokens);
+ if (tokens.length > 0) {
+ for (String token : tokens) {
+ for (String limiter : limiters) {
+ if (limiter.equals(token)) {
+ return sandboxNameParts.size() > 0
+ ? StringUtils.join(sandboxNameParts.toArray())
+ : null;
+ }
+ }
+ if (sandboxNameParts.size() > 0) {
+ sandboxNameParts.add(0, File.separator);
+ }
+ sandboxNameParts.add(0, token);
+ }
+ return StringUtils.join(sandboxNameParts.toArray());
+ } else {
+ return null;
+ }
+ }
}
diff --git a/dhp-build/dhp-build-properties-maven-plugin/src/main/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectProperties.java b/dhp-build/dhp-build-properties-maven-plugin/src/main/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectProperties.java
index 62f04761a9..d195ca86e4 100644
--- a/dhp-build/dhp-build-properties-maven-plugin/src/main/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectProperties.java
+++ b/dhp-build/dhp-build-properties-maven-plugin/src/main/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectProperties.java
@@ -1,17 +1,15 @@
/**
- *
- * Licensed under the Educational Community License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use
+ * this file except in compliance with the License. You may obtain a copy of the License at
*
- * http://www.opensource.org/licenses/ecl2.php
+ * http://www.opensource.org/licenses/ecl2.php
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ *
Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package eu.dnetlib.maven.plugin.properties;
import java.io.File;
@@ -41,346 +39,361 @@ import org.springframework.core.io.ResourceLoader;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
- * Writes project properties for the keys listed in specified properties files.
- * Based on:
- * http://site.kuali.org/maven/plugins/properties-maven-plugin/1.3.2/write-project-properties-mojo.html
-
+ * Writes project properties for the keys listed in specified properties files. Based on:
+ * http://site.kuali.org/maven/plugins/properties-maven-plugin/2.0.1/write-project-properties-mojo.html
+ *
* @author mhorst
* @goal write-project-properties
*/
public class WritePredefinedProjectProperties extends AbstractMojo {
-
+
private static final String CR = "\r";
private static final String LF = "\n";
private static final String TAB = "\t";
- protected static final String PROPERTY_PREFIX_ENV = "env.";
- private static final String ENCODING_UTF8 = "utf8";
-
- /**
- * @parameter property="properties.includePropertyKeysFromFiles"
- */
+ protected static final String PROPERTY_PREFIX_ENV = "env.";
+ private static final String ENCODING_UTF8 = "utf8";
+
+ /** @parameter property="properties.includePropertyKeysFromFiles" */
private String[] includePropertyKeysFromFiles;
-
- /**
- * @parameter default-value="${project}"
- * @required
- * @readonly
- */
- protected MavenProject project;
- /**
- * The file that properties will be written to
- *
- * @parameter property="properties.outputFile"
- * default-value="${project.build.directory}/properties/project.properties";
- * @required
- */
- protected File outputFile;
-
/**
- * If true, the plugin will silently ignore any non-existent properties files, and the build will continue
- *
- * @parameter property="properties.quiet" default-value="true"
- */
- private boolean quiet;
-
- /**
- * Comma separated list of characters to escape when writing property values. cr=carriage return, lf=linefeed,
- * tab=tab. Any other values are taken literally.
- *
- * @parameter default-value="cr,lf,tab" property="properties.escapeChars"
- */
- private String escapeChars;
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ */
+ protected MavenProject project;
- /**
- * If true, the plugin will include system properties when writing the properties file. System properties override
- * both environment variables and project properties.
- *
- * @parameter default-value="false" property="properties.includeSystemProperties"
- */
- private boolean includeSystemProperties;
+ /**
+ * The file that properties will be written to
+ *
+ * @parameter property="properties.outputFile"
+ * default-value="${project.build.directory}/properties/project.properties";
+ * @required
+ */
+ protected File outputFile;
- /**
- * If true, the plugin will include environment variables when writing the properties file. Environment variables
- * are prefixed with "env". Environment variables override project properties.
- *
- * @parameter default-value="false" property="properties.includeEnvironmentVariables"
- */
- private boolean includeEnvironmentVariables;
+ /**
+ * If true, the plugin will silently ignore any non-existent properties files, and the build will continue
+ *
+ * @parameter property="properties.quiet" default-value="true"
+ */
+ private boolean quiet;
- /**
- * Comma separated set of properties to exclude when writing the properties file
- *
- * @parameter property="properties.exclude"
- */
- private String exclude;
+ /**
+ * Comma separated list of characters to escape when writing property values. cr=carriage return, lf=linefeed,
+ * tab=tab. Any other values are taken literally.
+ *
+ * @parameter default-value="cr,lf,tab" property="properties.escapeChars"
+ */
+ private String escapeChars;
- /**
- * Comma separated set of properties to write to the properties file. If provided, only the properties matching
- * those supplied here will be written to the properties file.
- *
- * @parameter property="properties.include"
- */
- private String include;
+ /**
+ * If true, the plugin will include system properties when writing the properties file. System properties override
+ * both environment variables and project properties.
+ *
+ * @parameter default-value="false" property="properties.includeSystemProperties"
+ */
+ private boolean includeSystemProperties;
- /* (non-Javadoc)
- * @see org.apache.maven.plugin.AbstractMojo#execute()
- */
- @Override
- @SuppressFBWarnings({"NP_UNWRITTEN_FIELD","UWF_UNWRITTEN_FIELD"})
- public void execute() throws MojoExecutionException, MojoFailureException {
- Properties properties = new Properties();
- // Add project properties
- properties.putAll(project.getProperties());
- if (includeEnvironmentVariables) {
- // Add environment variables, overriding any existing properties with the same key
- properties.putAll(getEnvironmentVariables());
- }
- if (includeSystemProperties) {
- // Add system properties, overriding any existing properties with the same key
- properties.putAll(System.getProperties());
- }
+ /**
+ * If true, the plugin will include environment variables when writing the properties file. Environment variables
+ * are prefixed with "env". Environment variables override project properties.
+ *
+ * @parameter default-value="false" property="properties.includeEnvironmentVariables"
+ */
+ private boolean includeEnvironmentVariables;
- // Remove properties as appropriate
- trim(properties, exclude, include);
+ /**
+ * Comma separated set of properties to exclude when writing the properties file
+ *
+ * @parameter property="properties.exclude"
+ */
+ private String exclude;
- String comment = "# " + new Date() + "\n";
- List escapeTokens = getEscapeChars(escapeChars);
+ /**
+ * Comma separated set of properties to write to the properties file. If provided, only the properties matching
+ * those supplied here will be written to the properties file.
+ *
+ * @parameter property="properties.include"
+ */
+ private String include;
- getLog().info("Creating " + outputFile);
- writeProperties(outputFile, comment, properties, escapeTokens);
- }
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.AbstractMojo#execute()
+ */
+ @Override
+ @SuppressFBWarnings({
+ "NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD"
+ })
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ Properties properties = new Properties();
+ // Add project properties
+ properties.putAll(project.getProperties());
+ if (includeEnvironmentVariables) {
+ // Add environment variables, overriding any existing properties with the same key
+ properties.putAll(getEnvironmentVariables());
+ }
+ if (includeSystemProperties) {
+ // Add system properties, overriding any existing properties with the same key
+ properties.putAll(System.getProperties());
+ }
- /**
- * Provides environment variables.
- * @return environment variables
- */
- protected static Properties getEnvironmentVariables() {
- Properties props = new Properties();
- for (Entry entry : System.getenv().entrySet()) {
- props.setProperty(PROPERTY_PREFIX_ENV + entry.getKey(), entry.getValue());
- }
- return props;
- }
+ // Remove properties as appropriate
+ trim(properties, exclude, include);
- /**
- * Removes properties which should not be written.
- * @param properties
- * @param omitCSV
- * @param includeCSV
- * @throws MojoExecutionException
- */
- protected void trim(Properties properties, String omitCSV, String includeCSV) throws MojoExecutionException {
- List omitKeys = getListFromCSV(omitCSV);
- for (String key : omitKeys) {
- properties.remove(key);
- }
-
- List includeKeys = getListFromCSV(includeCSV);
-// mh: including keys from predefined properties
- if (includePropertyKeysFromFiles!=null && includePropertyKeysFromFiles.length>0) {
- for (String currentIncludeLoc : includePropertyKeysFromFiles) {
- if (validate(currentIncludeLoc)) {
- Properties p = getProperties(currentIncludeLoc);
- for (String key : p.stringPropertyNames()) {
- includeKeys.add(key);
- }
- }
- }
- }
- if (includeKeys!=null && !includeKeys.isEmpty()) {
-// removing only when include keys provided
- Set keys = properties.stringPropertyNames();
- for (String key : keys) {
- if (!includeKeys.contains(key)) {
- properties.remove(key);
- }
- }
- }
- }
+ String comment = "# " + new Date() + "\n";
+ List escapeTokens = getEscapeChars(escapeChars);
- /**
- * Checks whether file exists.
- * @param location
- * @return true when exists, false otherwise.
- */
- protected boolean exists(String location) {
- if (StringUtils.isBlank(location)) {
- return false;
- }
- File file = new File(location);
- if (file.exists()) {
- return true;
- }
- ResourceLoader loader = new DefaultResourceLoader();
- Resource resource = loader.getResource(location);
- return resource.exists();
- }
+ getLog().info("Creating " + outputFile);
+ writeProperties(outputFile, comment, properties, escapeTokens);
+ }
- /**
- * Validates resource location.
- * @param location
- * @return true when valid, false otherwise
- * @throws MojoExecutionException
- */
- protected boolean validate(String location) throws MojoExecutionException {
- boolean exists = exists(location);
- if (exists) {
- return true;
- }
- if (quiet) {
- getLog().info("Ignoring non-existent properties file '" + location + "'");
- return false;
- } else {
- throw new MojoExecutionException("Non-existent properties file '" + location + "'");
- }
- }
+ /**
+ * Provides environment variables.
+ *
+ * @return environment variables
+ */
+ protected static Properties getEnvironmentVariables() {
+ Properties props = new Properties();
+ for (Entry entry : System.getenv().entrySet()) {
+ props.setProperty(PROPERTY_PREFIX_ENV + entry.getKey(), entry.getValue());
+ }
+ return props;
+ }
- /**
- * Provides input stream.
- * @param location
- * @return input stream
- * @throws IOException
- */
- protected InputStream getInputStream(String location) throws IOException {
- File file = new File(location);
- if (file.exists()) {
- return new FileInputStream(location);
- }
- ResourceLoader loader = new DefaultResourceLoader();
- Resource resource = loader.getResource(location);
- return resource.getInputStream();
- }
+ /**
+ * Removes properties which should not be written.
+ *
+ * @param properties
+ * @param omitCSV
+ * @param includeCSV
+ * @throws MojoExecutionException
+ */
+ protected void trim(Properties properties, String omitCSV, String includeCSV)
+ throws MojoExecutionException {
+ List omitKeys = getListFromCSV(omitCSV);
+ for (String key : omitKeys) {
+ properties.remove(key);
+ }
- /**
- * Creates properties for given location.
- * @param location
- * @return properties for given location
- * @throws MojoExecutionException
- */
- protected Properties getProperties(String location) throws MojoExecutionException {
- InputStream in = null;
- try {
- Properties properties = new Properties();
- in = getInputStream(location);
- if (location.toLowerCase().endsWith(".xml")) {
- properties.loadFromXML(in);
- } else {
- properties.load(in);
- }
- return properties;
- } catch (IOException e) {
- throw new MojoExecutionException("Error reading properties file " + location, e);
- } finally {
- IOUtils.closeQuietly(in);
- }
- }
+ List includeKeys = getListFromCSV(includeCSV);
+ // mh: including keys from predefined properties
+ if (includePropertyKeysFromFiles != null && includePropertyKeysFromFiles.length > 0) {
+ for (String currentIncludeLoc : includePropertyKeysFromFiles) {
+ if (validate(currentIncludeLoc)) {
+ Properties p = getProperties(currentIncludeLoc);
+ for (String key : p.stringPropertyNames()) {
+ includeKeys.add(key);
+ }
+ }
+ }
+ }
+ if (includeKeys != null && !includeKeys.isEmpty()) {
+ // removing only when include keys provided
+ Set keys = properties.stringPropertyNames();
+ for (String key : keys) {
+ if (!includeKeys.contains(key)) {
+ properties.remove(key);
+ }
+ }
+ }
+ }
- /**
- * Provides escape characters.
- * @param escapeChars
- * @return escape characters
- */
- protected List getEscapeChars(String escapeChars) {
- List tokens = getListFromCSV(escapeChars);
- List realTokens = new ArrayList();
- for (String token : tokens) {
- String realToken = getRealToken(token);
- realTokens.add(realToken);
- }
- return realTokens;
- }
+ /**
+ * Checks whether file exists.
+ *
+ * @param location
+ * @return true when exists, false otherwise.
+ */
+ protected boolean exists(String location) {
+ if (StringUtils.isBlank(location)) {
+ return false;
+ }
+ File file = new File(location);
+ if (file.exists()) {
+ return true;
+ }
+ ResourceLoader loader = new DefaultResourceLoader();
+ Resource resource = loader.getResource(location);
+ return resource.exists();
+ }
- /**
- * Provides real token.
- * @param token
- * @return real token
- */
- protected String getRealToken(String token) {
- if (token.equalsIgnoreCase("CR")) {
- return CR;
- } else if (token.equalsIgnoreCase("LF")) {
- return LF;
- } else if (token.equalsIgnoreCase("TAB")) {
- return TAB;
- } else {
- return token;
- }
- }
+ /**
+ * Validates resource location.
+ *
+ * @param location
+ * @return true when valid, false otherwise
+ * @throws MojoExecutionException
+ */
+ protected boolean validate(String location) throws MojoExecutionException {
+ boolean exists = exists(location);
+ if (exists) {
+ return true;
+ }
+ if (quiet) {
+ getLog().info("Ignoring non-existent properties file '" + location + "'");
+ return false;
+ } else {
+ throw new MojoExecutionException("Non-existent properties file '" + location + "'");
+ }
+ }
- /**
- * Returns content.
- * @param comment
- * @param properties
- * @param escapeTokens
- * @return content
- */
- protected String getContent(String comment, Properties properties, List escapeTokens) {
- List names = new ArrayList(properties.stringPropertyNames());
- Collections.sort(names);
- StringBuilder sb = new StringBuilder();
- if (!StringUtils.isBlank(comment)) {
- sb.append(comment);
- }
- for (String name : names) {
- String value = properties.getProperty(name);
- String escapedValue = escape(value, escapeTokens);
- sb.append(name + "=" + escapedValue + "\n");
- }
- return sb.toString();
- }
+ /**
+ * Provides input stream.
+ *
+ * @param location
+ * @return input stream
+ * @throws IOException
+ */
+ protected InputStream getInputStream(String location) throws IOException {
+ File file = new File(location);
+ if (file.exists()) {
+ return new FileInputStream(location);
+ }
+ ResourceLoader loader = new DefaultResourceLoader();
+ Resource resource = loader.getResource(location);
+ return resource.getInputStream();
+ }
- /**
- * Writes properties to given file.
- * @param file
- * @param comment
- * @param properties
- * @param escapeTokens
- * @throws MojoExecutionException
- */
- protected void writeProperties(File file, String comment, Properties properties, List escapeTokens)
- throws MojoExecutionException {
- try {
- String content = getContent(comment, properties, escapeTokens);
- FileUtils.writeStringToFile(file, content, ENCODING_UTF8);
- } catch (IOException e) {
- throw new MojoExecutionException("Error creating properties file", e);
- }
- }
-
- /**
- * Escapes characters.
- * @param s
- * @param escapeChars
- * @return
- */
- protected String escape(String s, List escapeChars) {
- String result = s;
- for (String escapeChar : escapeChars) {
- result = result.replace(escapeChar, getReplacementToken(escapeChar));
- }
- return result;
- }
+ /**
+ * Creates properties for given location.
+ *
+ * @param location
+ * @return properties for given location
+ * @throws MojoExecutionException
+ */
+ protected Properties getProperties(String location) throws MojoExecutionException {
+ InputStream in = null;
+ try {
+ Properties properties = new Properties();
+ in = getInputStream(location);
+ if (location.toLowerCase().endsWith(".xml")) {
+ properties.loadFromXML(in);
+ } else {
+ properties.load(in);
+ }
+ return properties;
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error reading properties file " + location, e);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
- /**
- * Provides replacement token.
- * @param escapeChar
- * @return replacement token
- */
- protected String getReplacementToken(String escapeChar) {
- if (escapeChar.equals(CR)) {
- return "\\r";
- } else if (escapeChar.equals(LF)) {
- return "\\n";
- } else if (escapeChar.equals(TAB)) {
- return "\\t";
- } else {
- return "\\" + escapeChar;
- }
- }
+ /**
+ * Provides escape characters.
+ *
+ * @param escapeChars
+ * @return escape characters
+ */
+ protected List getEscapeChars(String escapeChars) {
+ List tokens = getListFromCSV(escapeChars);
+ List realTokens = new ArrayList();
+ for (String token : tokens) {
+ String realToken = getRealToken(token);
+ realTokens.add(realToken);
+ }
+ return realTokens;
+ }
- /**
+ /**
+ * Provides real token.
+ *
+ * @param token
+ * @return real token
+ */
+ protected String getRealToken(String token) {
+ if (token.equalsIgnoreCase("CR")) {
+ return CR;
+ } else if (token.equalsIgnoreCase("LF")) {
+ return LF;
+ } else if (token.equalsIgnoreCase("TAB")) {
+ return TAB;
+ } else {
+ return token;
+ }
+ }
+
+ /**
+ * Returns content.
+ *
+ * @param comment
+ * @param properties
+ * @param escapeTokens
+ * @return content
+ */
+ protected String getContent(String comment, Properties properties, List escapeTokens) {
+ List names = new ArrayList(properties.stringPropertyNames());
+ Collections.sort(names);
+ StringBuilder sb = new StringBuilder();
+ if (!StringUtils.isBlank(comment)) {
+ sb.append(comment);
+ }
+ for (String name : names) {
+ String value = properties.getProperty(name);
+ String escapedValue = escape(value, escapeTokens);
+ sb.append(name + "=" + escapedValue + "\n");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Writes properties to given file.
+ *
+ * @param file
+ * @param comment
+ * @param properties
+ * @param escapeTokens
+ * @throws MojoExecutionException
+ */
+ protected void writeProperties(
+ File file, String comment, Properties properties, List escapeTokens)
+ throws MojoExecutionException {
+ try {
+ String content = getContent(comment, properties, escapeTokens);
+ FileUtils.writeStringToFile(file, content, ENCODING_UTF8);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error creating properties file", e);
+ }
+ }
+
+ /**
+ * Escapes characters.
+ *
+ * @param s
+ * @param escapeChars
+ * @return
+ */
+ protected String escape(String s, List escapeChars) {
+ String result = s;
+ for (String escapeChar : escapeChars) {
+ result = result.replace(escapeChar, getReplacementToken(escapeChar));
+ }
+ return result;
+ }
+
+ /**
+ * Provides replacement token.
+ *
+ * @param escapeChar
+ * @return replacement token
+ */
+ protected String getReplacementToken(String escapeChar) {
+ if (escapeChar.equals(CR)) {
+ return "\\r";
+ } else if (escapeChar.equals(LF)) {
+ return "\\n";
+ } else if (escapeChar.equals(TAB)) {
+ return "\\t";
+ } else {
+ return "\\" + escapeChar;
+ }
+ }
+
+ /**
* Returns list from csv.
+ *
* @param csv
* @return list of values generated from CSV
*/
@@ -396,41 +409,39 @@ public class WritePredefinedProjectProperties extends AbstractMojo {
return list;
}
- public void setIncludeSystemProperties(boolean includeSystemProperties) {
- this.includeSystemProperties = includeSystemProperties;
- }
+ public void setIncludeSystemProperties(boolean includeSystemProperties) {
+ this.includeSystemProperties = includeSystemProperties;
+ }
- public void setEscapeChars(String escapeChars) {
- this.escapeChars = escapeChars;
- }
+ public void setEscapeChars(String escapeChars) {
+ this.escapeChars = escapeChars;
+ }
- public void setIncludeEnvironmentVariables(boolean includeEnvironmentVariables) {
- this.includeEnvironmentVariables = includeEnvironmentVariables;
- }
+ public void setIncludeEnvironmentVariables(boolean includeEnvironmentVariables) {
+ this.includeEnvironmentVariables = includeEnvironmentVariables;
+ }
- public void setExclude(String exclude) {
- this.exclude = exclude;
- }
+ public void setExclude(String exclude) {
+ this.exclude = exclude;
+ }
- public void setInclude(String include) {
- this.include = include;
- }
+ public void setInclude(String include) {
+ this.include = include;
+ }
+
+ public void setQuiet(boolean quiet) {
+ this.quiet = quiet;
+ }
- public void setQuiet(boolean quiet) {
- this.quiet = quiet;
- }
-
/**
* Sets property files for which keys properties should be included.
+ *
* @param includePropertyKeysFromFiles
*/
- public void setIncludePropertyKeysFromFiles(
- String[] includePropertyKeysFromFiles) {
- if (includePropertyKeysFromFiles!=null) {
- this.includePropertyKeysFromFiles = Arrays.copyOf(
- includePropertyKeysFromFiles,
- includePropertyKeysFromFiles.length);
+ public void setIncludePropertyKeysFromFiles(String[] includePropertyKeysFromFiles) {
+ if (includePropertyKeysFromFiles != null) {
+ this.includePropertyKeysFromFiles = Arrays
+ .copyOf(includePropertyKeysFromFiles, includePropertyKeysFromFiles.length);
}
}
-
-}
\ No newline at end of file
+}
diff --git a/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/GenerateOoziePropertiesMojoTest.java b/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/GenerateOoziePropertiesMojoTest.java
index a2cb8e0f1e..4bfcd3b33e 100644
--- a/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/GenerateOoziePropertiesMojoTest.java
+++ b/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/GenerateOoziePropertiesMojoTest.java
@@ -1,100 +1,97 @@
-package eu.dnetlib.maven.plugin.properties;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
+package eu.dnetlib.maven.plugin.properties;
import static eu.dnetlib.maven.plugin.properties.GenerateOoziePropertiesMojo.PROPERTY_NAME_SANDBOX_NAME;
import static eu.dnetlib.maven.plugin.properties.GenerateOoziePropertiesMojo.PROPERTY_NAME_WF_SOURCE_DIR;
import static org.junit.jupiter.api.Assertions.*;
-/**
- * @author mhorst, claudio.atzori
- *
- */
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** @author mhorst, claudio.atzori */
public class GenerateOoziePropertiesMojoTest {
- private GenerateOoziePropertiesMojo mojo = new GenerateOoziePropertiesMojo();
-
- @BeforeEach
- public void clearSystemProperties() {
- System.clearProperty(PROPERTY_NAME_SANDBOX_NAME);
- System.clearProperty(PROPERTY_NAME_WF_SOURCE_DIR);
- }
-
- @Test
- public void testExecuteEmpty() throws Exception {
- // execute
- mojo.execute();
-
- // assert
- assertNull(System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
- }
+ private final GenerateOoziePropertiesMojo mojo = new GenerateOoziePropertiesMojo();
- @Test
- public void testExecuteSandboxNameAlreadySet() throws Exception {
- // given
- String workflowSourceDir = "eu/dnetlib/dhp/wf/transformers";
- String sandboxName = "originalSandboxName";
- System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
- System.setProperty(PROPERTY_NAME_SANDBOX_NAME, sandboxName);
-
- // execute
- mojo.execute();
-
- // assert
- assertEquals(sandboxName, System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
- }
-
- @Test
- public void testExecuteEmptyWorkflowSourceDir() throws Exception {
- // given
- String workflowSourceDir = "";
- System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
-
- // execute
- mojo.execute();
-
- // assert
- assertNull(System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
- }
-
- @Test
- public void testExecuteNullSandboxNameGenerated() throws Exception {
- // given
- String workflowSourceDir = "eu/dnetlib/dhp/";
- System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
-
- // execute
- mojo.execute();
-
- // assert
- assertNull(System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
- }
-
- @Test
- public void testExecute() throws Exception {
- // given
- String workflowSourceDir = "eu/dnetlib/dhp/wf/transformers";
- System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
-
- // execute
- mojo.execute();
-
- // assert
- assertEquals("wf/transformers", System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
- }
-
- @Test
- public void testExecuteWithoutRoot() throws Exception {
- // given
- String workflowSourceDir = "wf/transformers";
- System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
-
- // execute
- mojo.execute();
-
- // assert
- assertEquals("wf/transformers", System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
- }
-
+ @BeforeEach
+ public void clearSystemProperties() {
+ System.clearProperty(PROPERTY_NAME_SANDBOX_NAME);
+ System.clearProperty(PROPERTY_NAME_WF_SOURCE_DIR);
+ }
+
+ @Test
+ public void testExecuteEmpty() throws Exception {
+ // execute
+ mojo.execute();
+
+ // assert
+ assertNull(System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
+ }
+
+ @Test
+ public void testExecuteSandboxNameAlreadySet() throws Exception {
+ // given
+ String workflowSourceDir = "eu/dnetlib/dhp/wf/transformers";
+ String sandboxName = "originalSandboxName";
+ System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
+ System.setProperty(PROPERTY_NAME_SANDBOX_NAME, sandboxName);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertEquals(sandboxName, System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
+ }
+
+ @Test
+ public void testExecuteEmptyWorkflowSourceDir() throws Exception {
+ // given
+ String workflowSourceDir = "";
+ System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertNull(System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
+ }
+
+ @Test
+ public void testExecuteNullSandboxNameGenerated() throws Exception {
+ // given
+ String workflowSourceDir = "eu/dnetlib/dhp/";
+ System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertNull(System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
+ }
+
+ @Test
+ public void testExecute() throws Exception {
+ // given
+ String workflowSourceDir = "eu/dnetlib/dhp/wf/transformers";
+ System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertEquals("wf/transformers", System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
+ }
+
+ @Test
+ public void testExecuteWithoutRoot() throws Exception {
+ // given
+ String workflowSourceDir = "wf/transformers";
+ System.setProperty(PROPERTY_NAME_WF_SOURCE_DIR, workflowSourceDir);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertEquals("wf/transformers", System.getProperty(PROPERTY_NAME_SANDBOX_NAME));
+ }
}
diff --git a/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectPropertiesTest.java b/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectPropertiesTest.java
index 4b72130787..0b3ea9653b 100644
--- a/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectPropertiesTest.java
+++ b/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectPropertiesTest.java
@@ -1,5 +1,14 @@
+
package eu.dnetlib.maven.plugin.properties;
+import static eu.dnetlib.maven.plugin.properties.WritePredefinedProjectProperties.PROPERTY_PREFIX_ENV;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
+
+import java.io.*;
+import java.util.Properties;
+
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.junit.jupiter.api.*;
@@ -9,347 +18,357 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
-import java.io.*;
-import java.util.Properties;
-
-import static eu.dnetlib.maven.plugin.properties.WritePredefinedProjectProperties.PROPERTY_PREFIX_ENV;
-import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.lenient;
-
-/**
- * @author mhorst, claudio.atzori
- *
- */
+/** @author mhorst, claudio.atzori */
@ExtendWith(MockitoExtension.class)
public class WritePredefinedProjectPropertiesTest {
- @Mock
- private MavenProject mavenProject;
-
- private WritePredefinedProjectProperties mojo;
+ @Mock
+ private MavenProject mavenProject;
- @BeforeEach
- public void init(@TempDir File testFolder) {
- MockitoAnnotations.initMocks(this);
- mojo = new WritePredefinedProjectProperties();
- mojo.outputFile = getPropertiesFileLocation(testFolder);
- mojo.project = mavenProject;
- lenient().doReturn(new Properties()).when(mavenProject).getProperties();
- }
+ private WritePredefinedProjectProperties mojo;
- // ----------------------------------- TESTS ---------------------------------------------
-
- @Test
- public void testExecuteEmpty() throws Exception {
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(mojo.outputFile.getParentFile());
- assertEquals(0, storedProperties.size());
- }
-
- @Test
- public void testExecuteWithProjectProperties() throws Exception {
- // given
- String key = "projectPropertyKey";
- String value = "projectPropertyValue";
- Properties projectProperties = new Properties();
- projectProperties.setProperty(key, value);
- doReturn(projectProperties).when(mavenProject).getProperties();
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(mojo.outputFile.getParentFile());
- assertEquals(1, storedProperties.size());
- assertTrue(storedProperties.containsKey(key));
- assertEquals(value, storedProperties.getProperty(key));
- }
-
- @Test()
- public void testExecuteWithProjectPropertiesAndInvalidOutputFile(@TempDir File testFolder) {
- // given
- String key = "projectPropertyKey";
- String value = "projectPropertyValue";
- Properties projectProperties = new Properties();
- projectProperties.setProperty(key, value);
- doReturn(projectProperties).when(mavenProject).getProperties();
- mojo.outputFile = testFolder;
-
- // execute
- Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
- }
-
- @Test
- public void testExecuteWithProjectPropertiesExclusion(@TempDir File testFolder) throws Exception {
- // given
- String key = "projectPropertyKey";
- String value = "projectPropertyValue";
- String excludedKey = "excludedPropertyKey";
- String excludedValue = "excludedPropertyValue";
- Properties projectProperties = new Properties();
- projectProperties.setProperty(key, value);
- projectProperties.setProperty(excludedKey, excludedValue);
- doReturn(projectProperties).when(mavenProject).getProperties();
- mojo.setExclude(excludedKey);
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(testFolder);
- assertEquals(1, storedProperties.size());
- assertTrue(storedProperties.containsKey(key));
- assertEquals(value, storedProperties.getProperty(key));
- }
-
- @Test
- public void testExecuteWithProjectPropertiesInclusion(@TempDir File testFolder) throws Exception {
- // given
- String key = "projectPropertyKey";
- String value = "projectPropertyValue";
- String includedKey = "includedPropertyKey";
- String includedValue = "includedPropertyValue";
- Properties projectProperties = new Properties();
- projectProperties.setProperty(key, value);
- projectProperties.setProperty(includedKey, includedValue);
- doReturn(projectProperties).when(mavenProject).getProperties();
- mojo.setInclude(includedKey);
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(testFolder);
- assertEquals(1, storedProperties.size());
- assertTrue(storedProperties.containsKey(includedKey));
- assertEquals(includedValue, storedProperties.getProperty(includedKey));
- }
-
- @Test
- public void testExecuteIncludingPropertyKeysFromFile(@TempDir File testFolder) throws Exception {
- // given
- String key = "projectPropertyKey";
- String value = "projectPropertyValue";
- String includedKey = "includedPropertyKey";
- String includedValue = "includedPropertyValue";
- Properties projectProperties = new Properties();
- projectProperties.setProperty(key, value);
- projectProperties.setProperty(includedKey, includedValue);
- doReturn(projectProperties).when(mavenProject).getProperties();
-
- File includedPropertiesFile = new File(testFolder, "included.properties");
- Properties includedProperties = new Properties();
- includedProperties.setProperty(includedKey, "irrelevantValue");
- includedProperties.store(new FileWriter(includedPropertiesFile), null);
-
- mojo.setIncludePropertyKeysFromFiles(new String[] {includedPropertiesFile.getAbsolutePath()});
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(testFolder);
- assertEquals(1, storedProperties.size());
- assertTrue(storedProperties.containsKey(includedKey));
- assertEquals(includedValue, storedProperties.getProperty(includedKey));
- }
-
- @Test
- public void testExecuteIncludingPropertyKeysFromClasspathResource(@TempDir File testFolder) throws Exception {
- // given
- String key = "projectPropertyKey";
- String value = "projectPropertyValue";
- String includedKey = "includedPropertyKey";
- String includedValue = "includedPropertyValue";
- Properties projectProperties = new Properties();
- projectProperties.setProperty(key, value);
- projectProperties.setProperty(includedKey, includedValue);
- doReturn(projectProperties).when(mavenProject).getProperties();
-
- mojo.setIncludePropertyKeysFromFiles(new String[] {"/eu/dnetlib/maven/plugin/properties/included.properties"});
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(testFolder);
- assertEquals(1, storedProperties.size());
- assertTrue(storedProperties.containsKey(includedKey));
- assertEquals(includedValue, storedProperties.getProperty(includedKey));
- }
-
- @Test
- public void testExecuteIncludingPropertyKeysFromBlankLocation() {
- // given
- String key = "projectPropertyKey";
- String value = "projectPropertyValue";
- String includedKey = "includedPropertyKey";
- String includedValue = "includedPropertyValue";
- Properties projectProperties = new Properties();
- projectProperties.setProperty(key, value);
- projectProperties.setProperty(includedKey, includedValue);
- doReturn(projectProperties).when(mavenProject).getProperties();
-
- mojo.setIncludePropertyKeysFromFiles(new String[] {""});
-
- // execute
- Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
- }
-
- @Test
- public void testExecuteIncludingPropertyKeysFromXmlFile(@TempDir File testFolder) throws Exception {
- // given
- String key = "projectPropertyKey";
- String value = "projectPropertyValue";
- String includedKey = "includedPropertyKey";
- String includedValue = "includedPropertyValue";
- Properties projectProperties = new Properties();
- projectProperties.setProperty(key, value);
- projectProperties.setProperty(includedKey, includedValue);
- doReturn(projectProperties).when(mavenProject).getProperties();
-
- File includedPropertiesFile = new File(testFolder, "included.xml");
- Properties includedProperties = new Properties();
- includedProperties.setProperty(includedKey, "irrelevantValue");
- includedProperties.storeToXML(new FileOutputStream(includedPropertiesFile), null);
-
- mojo.setIncludePropertyKeysFromFiles(new String[] {includedPropertiesFile.getAbsolutePath()});
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(testFolder);
- assertEquals(1, storedProperties.size());
- assertTrue(storedProperties.containsKey(includedKey));
- assertEquals(includedValue, storedProperties.getProperty(includedKey));
- }
-
- @Test
- public void testExecuteIncludingPropertyKeysFromInvalidXmlFile(@TempDir File testFolder) throws Exception {
- // given
- String key = "projectPropertyKey";
- String value = "projectPropertyValue";
- String includedKey = "includedPropertyKey";
- String includedValue = "includedPropertyValue";
- Properties projectProperties = new Properties();
- projectProperties.setProperty(key, value);
- projectProperties.setProperty(includedKey, includedValue);
- doReturn(projectProperties).when(mavenProject).getProperties();
-
- File includedPropertiesFile = new File(testFolder, "included.xml");
- Properties includedProperties = new Properties();
- includedProperties.setProperty(includedKey, "irrelevantValue");
- includedProperties.store(new FileOutputStream(includedPropertiesFile), null);
-
- mojo.setIncludePropertyKeysFromFiles(new String[] {includedPropertiesFile.getAbsolutePath()});
-
- // execute
- Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
- }
-
- @Test
- public void testExecuteWithQuietModeOn(@TempDir File testFolder) throws Exception {
- // given
- mojo.setQuiet(true);
- mojo.setIncludePropertyKeysFromFiles(new String[] {"invalid location"});
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(testFolder);
- assertEquals(0, storedProperties.size());
- }
-
- @Test
- public void testExecuteIncludingPropertyKeysFromInvalidFile() {
- // given
- mojo.setIncludePropertyKeysFromFiles(new String[] {"invalid location"});
-
- // execute
- Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
- }
-
- @Test
- public void testExecuteWithEnvironmentProperties(@TempDir File testFolder) throws Exception {
- // given
- mojo.setIncludeEnvironmentVariables(true);
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(testFolder);
- assertTrue(storedProperties.size() > 0);
- for (Object currentKey : storedProperties.keySet()) {
- assertTrue(((String)currentKey).startsWith(PROPERTY_PREFIX_ENV));
- }
- }
-
- @Test
- public void testExecuteWithSystemProperties(@TempDir File testFolder) throws Exception {
- // given
- String key = "systemPropertyKey";
- String value = "systemPropertyValue";
- System.setProperty(key, value);
- mojo.setIncludeSystemProperties(true);
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(testFolder);
- assertTrue(storedProperties.size() > 0);
- assertTrue(storedProperties.containsKey(key));
- assertEquals(value, storedProperties.getProperty(key));
- }
-
- @Test
- public void testExecuteWithSystemPropertiesAndEscapeChars(@TempDir File testFolder) throws Exception {
- // given
- String key = "systemPropertyKey ";
- String value = "systemPropertyValue";
- System.setProperty(key, value);
- mojo.setIncludeSystemProperties(true);
- String escapeChars = "cr,lf,tab,|";
- mojo.setEscapeChars(escapeChars);
-
- // execute
- mojo.execute();
-
- // assert
- assertTrue(mojo.outputFile.exists());
- Properties storedProperties = getStoredProperties(testFolder);
- assertTrue(storedProperties.size() > 0);
- assertFalse(storedProperties.containsKey(key));
- assertTrue(storedProperties.containsKey(key.trim()));
- assertEquals(value, storedProperties.getProperty(key.trim()));
- }
-
- // ----------------------------------- PRIVATE -------------------------------------------
-
- private File getPropertiesFileLocation(File testFolder) {
- return new File(testFolder, "test.properties");
- }
-
- private Properties getStoredProperties(File testFolder) throws FileNotFoundException, IOException {
- Properties properties = new Properties();
- properties.load(new FileInputStream(getPropertiesFileLocation(testFolder)));
- return properties;
- }
+ @BeforeEach
+ public void init(@TempDir File testFolder) {
+ MockitoAnnotations.initMocks(this);
+ mojo = new WritePredefinedProjectProperties();
+ mojo.outputFile = getPropertiesFileLocation(testFolder);
+ mojo.project = mavenProject;
+ lenient().doReturn(new Properties()).when(mavenProject).getProperties();
+ }
+
+ // ----------------------------------- TESTS ---------------------------------------------
+
+ @Test
+ public void testExecuteEmpty() throws Exception {
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(mojo.outputFile.getParentFile());
+ assertEquals(0, storedProperties.size());
+ }
+
+ @Test
+ public void testExecuteWithProjectProperties() throws Exception {
+ // given
+ String key = "projectPropertyKey";
+ String value = "projectPropertyValue";
+ Properties projectProperties = new Properties();
+ projectProperties.setProperty(key, value);
+ doReturn(projectProperties).when(mavenProject).getProperties();
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(mojo.outputFile.getParentFile());
+ assertEquals(1, storedProperties.size());
+ assertTrue(storedProperties.containsKey(key));
+ assertEquals(value, storedProperties.getProperty(key));
+ }
+
+ @Test()
+ public void testExecuteWithProjectPropertiesAndInvalidOutputFile(@TempDir File testFolder) {
+ // given
+ String key = "projectPropertyKey";
+ String value = "projectPropertyValue";
+ Properties projectProperties = new Properties();
+ projectProperties.setProperty(key, value);
+ doReturn(projectProperties).when(mavenProject).getProperties();
+ mojo.outputFile = testFolder;
+
+ // execute
+ Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
+ }
+
+ @Test
+ public void testExecuteWithProjectPropertiesExclusion(@TempDir File testFolder) throws Exception {
+ // given
+ String key = "projectPropertyKey";
+ String value = "projectPropertyValue";
+ String excludedKey = "excludedPropertyKey";
+ String excludedValue = "excludedPropertyValue";
+ Properties projectProperties = new Properties();
+ projectProperties.setProperty(key, value);
+ projectProperties.setProperty(excludedKey, excludedValue);
+ doReturn(projectProperties).when(mavenProject).getProperties();
+ mojo.setExclude(excludedKey);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(testFolder);
+ assertEquals(1, storedProperties.size());
+ assertTrue(storedProperties.containsKey(key));
+ assertEquals(value, storedProperties.getProperty(key));
+ }
+
+ @Test
+ public void testExecuteWithProjectPropertiesInclusion(@TempDir File testFolder) throws Exception {
+ // given
+ String key = "projectPropertyKey";
+ String value = "projectPropertyValue";
+ String includedKey = "includedPropertyKey";
+ String includedValue = "includedPropertyValue";
+ Properties projectProperties = new Properties();
+ projectProperties.setProperty(key, value);
+ projectProperties.setProperty(includedKey, includedValue);
+ doReturn(projectProperties).when(mavenProject).getProperties();
+ mojo.setInclude(includedKey);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(testFolder);
+ assertEquals(1, storedProperties.size());
+ assertTrue(storedProperties.containsKey(includedKey));
+ assertEquals(includedValue, storedProperties.getProperty(includedKey));
+ }
+
+ @Test
+ public void testExecuteIncludingPropertyKeysFromFile(@TempDir File testFolder) throws Exception {
+ // given
+ String key = "projectPropertyKey";
+ String value = "projectPropertyValue";
+ String includedKey = "includedPropertyKey";
+ String includedValue = "includedPropertyValue";
+ Properties projectProperties = new Properties();
+ projectProperties.setProperty(key, value);
+ projectProperties.setProperty(includedKey, includedValue);
+ doReturn(projectProperties).when(mavenProject).getProperties();
+
+ File includedPropertiesFile = new File(testFolder, "included.properties");
+ Properties includedProperties = new Properties();
+ includedProperties.setProperty(includedKey, "irrelevantValue");
+ includedProperties.store(new FileWriter(includedPropertiesFile), null);
+
+ mojo.setIncludePropertyKeysFromFiles(new String[] {
+ includedPropertiesFile.getAbsolutePath()
+ });
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(testFolder);
+ assertEquals(1, storedProperties.size());
+ assertTrue(storedProperties.containsKey(includedKey));
+ assertEquals(includedValue, storedProperties.getProperty(includedKey));
+ }
+
+ @Test
+ public void testExecuteIncludingPropertyKeysFromClasspathResource(@TempDir File testFolder)
+ throws Exception {
+ // given
+ String key = "projectPropertyKey";
+ String value = "projectPropertyValue";
+ String includedKey = "includedPropertyKey";
+ String includedValue = "includedPropertyValue";
+ Properties projectProperties = new Properties();
+ projectProperties.setProperty(key, value);
+ projectProperties.setProperty(includedKey, includedValue);
+ doReturn(projectProperties).when(mavenProject).getProperties();
+
+ mojo
+ .setIncludePropertyKeysFromFiles(
+ new String[] {
+ "/eu/dnetlib/maven/plugin/properties/included.properties"
+ });
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(testFolder);
+ assertEquals(1, storedProperties.size());
+ assertTrue(storedProperties.containsKey(includedKey));
+ assertEquals(includedValue, storedProperties.getProperty(includedKey));
+ }
+
+ @Test
+ public void testExecuteIncludingPropertyKeysFromBlankLocation() {
+ // given
+ String key = "projectPropertyKey";
+ String value = "projectPropertyValue";
+ String includedKey = "includedPropertyKey";
+ String includedValue = "includedPropertyValue";
+ Properties projectProperties = new Properties();
+ projectProperties.setProperty(key, value);
+ projectProperties.setProperty(includedKey, includedValue);
+ doReturn(projectProperties).when(mavenProject).getProperties();
+
+ mojo.setIncludePropertyKeysFromFiles(new String[] {
+ ""
+ });
+
+ // execute
+ Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
+ }
+
+ @Test
+ public void testExecuteIncludingPropertyKeysFromXmlFile(@TempDir File testFolder)
+ throws Exception {
+ // given
+ String key = "projectPropertyKey";
+ String value = "projectPropertyValue";
+ String includedKey = "includedPropertyKey";
+ String includedValue = "includedPropertyValue";
+ Properties projectProperties = new Properties();
+ projectProperties.setProperty(key, value);
+ projectProperties.setProperty(includedKey, includedValue);
+ doReturn(projectProperties).when(mavenProject).getProperties();
+
+ File includedPropertiesFile = new File(testFolder, "included.xml");
+ Properties includedProperties = new Properties();
+ includedProperties.setProperty(includedKey, "irrelevantValue");
+ includedProperties.storeToXML(new FileOutputStream(includedPropertiesFile), null);
+
+ mojo.setIncludePropertyKeysFromFiles(new String[] {
+ includedPropertiesFile.getAbsolutePath()
+ });
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(testFolder);
+ assertEquals(1, storedProperties.size());
+ assertTrue(storedProperties.containsKey(includedKey));
+ assertEquals(includedValue, storedProperties.getProperty(includedKey));
+ }
+
+ @Test
+ public void testExecuteIncludingPropertyKeysFromInvalidXmlFile(@TempDir File testFolder)
+ throws Exception {
+ // given
+ String key = "projectPropertyKey";
+ String value = "projectPropertyValue";
+ String includedKey = "includedPropertyKey";
+ String includedValue = "includedPropertyValue";
+ Properties projectProperties = new Properties();
+ projectProperties.setProperty(key, value);
+ projectProperties.setProperty(includedKey, includedValue);
+ doReturn(projectProperties).when(mavenProject).getProperties();
+
+ File includedPropertiesFile = new File(testFolder, "included.xml");
+ Properties includedProperties = new Properties();
+ includedProperties.setProperty(includedKey, "irrelevantValue");
+ includedProperties.store(new FileOutputStream(includedPropertiesFile), null);
+
+ mojo.setIncludePropertyKeysFromFiles(new String[] {
+ includedPropertiesFile.getAbsolutePath()
+ });
+
+ // execute
+ Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
+ }
+
+ @Test
+ public void testExecuteWithQuietModeOn(@TempDir File testFolder) throws Exception {
+ // given
+ mojo.setQuiet(true);
+ mojo.setIncludePropertyKeysFromFiles(new String[] {
+ "invalid location"
+ });
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(testFolder);
+ assertEquals(0, storedProperties.size());
+ }
+
+ @Test
+ public void testExecuteIncludingPropertyKeysFromInvalidFile() {
+ // given
+ mojo.setIncludePropertyKeysFromFiles(new String[] {
+ "invalid location"
+ });
+
+ // execute
+ Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
+ }
+
+ @Test
+ public void testExecuteWithEnvironmentProperties(@TempDir File testFolder) throws Exception {
+ // given
+ mojo.setIncludeEnvironmentVariables(true);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(testFolder);
+ assertTrue(storedProperties.size() > 0);
+ for (Object currentKey : storedProperties.keySet()) {
+ assertTrue(((String) currentKey).startsWith(PROPERTY_PREFIX_ENV));
+ }
+ }
+
+ @Test
+ public void testExecuteWithSystemProperties(@TempDir File testFolder) throws Exception {
+ // given
+ String key = "systemPropertyKey";
+ String value = "systemPropertyValue";
+ System.setProperty(key, value);
+ mojo.setIncludeSystemProperties(true);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(testFolder);
+ assertTrue(storedProperties.size() > 0);
+ assertTrue(storedProperties.containsKey(key));
+ assertEquals(value, storedProperties.getProperty(key));
+ }
+
+ @Test
+ public void testExecuteWithSystemPropertiesAndEscapeChars(@TempDir File testFolder)
+ throws Exception {
+ // given
+ String key = "systemPropertyKey ";
+ String value = "systemPropertyValue";
+ System.setProperty(key, value);
+ mojo.setIncludeSystemProperties(true);
+ String escapeChars = "cr,lf,tab,|";
+ mojo.setEscapeChars(escapeChars);
+
+ // execute
+ mojo.execute();
+
+ // assert
+ assertTrue(mojo.outputFile.exists());
+ Properties storedProperties = getStoredProperties(testFolder);
+ assertTrue(storedProperties.size() > 0);
+ assertFalse(storedProperties.containsKey(key));
+ assertTrue(storedProperties.containsKey(key.trim()));
+ assertEquals(value, storedProperties.getProperty(key.trim()));
+ }
+
+ // ----------------------------------- PRIVATE -------------------------------------------
+
+ private File getPropertiesFileLocation(File testFolder) {
+ return new File(testFolder, "test.properties");
+ }
+
+ private Properties getStoredProperties(File testFolder)
+ throws IOException {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(getPropertiesFileLocation(testFolder)));
+ return properties;
+ }
}
diff --git a/dhp-build/dhp-code-style/pom.xml b/dhp-build/dhp-code-style/pom.xml
new file mode 100644
index 0000000000..5e896e7a5c
--- /dev/null
+++ b/dhp-build/dhp-code-style/pom.xml
@@ -0,0 +1,50 @@
+
+
+
+ 4.0.0
+
+ eu.dnetlib.dhp
+ dhp-code-style
+ 1.1.7-SNAPSHOT
+
+ jar
+
+ This module contains resources supporting common code style conventions
+
+
+
+ dnet45-snapshots
+ DNet45 Snapshots
+ http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots
+ default
+
+
+ dnet45-releases
+ http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-releases
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-project-info-reports-plugin
+ 3.0.0
+
+
+ org.apache.maven.plugins
+ maven-site-plugin
+ 3.7.1
+
+
+
+
+
+
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_aosp.xml b/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_aosp.xml
new file mode 100644
index 0000000000..d58709f748
--- /dev/null
+++ b/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_aosp.xml
@@ -0,0 +1,252 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_dnet.xml b/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_dnet.xml
new file mode 100644
index 0000000000..fcba2c4b29
--- /dev/null
+++ b/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_dnet.xml
@@ -0,0 +1,727 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_google.xml b/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_google.xml
new file mode 100644
index 0000000000..56e5079242
--- /dev/null
+++ b/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_google.xml
@@ -0,0 +1,337 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dhp-build/pom.xml b/dhp-build/pom.xml
index 3b54b4e61a..041641fcfb 100644
--- a/dhp-build/pom.xml
+++ b/dhp-build/pom.xml
@@ -8,7 +8,11 @@
dhp-build
pom
+
+ This module is a container for the build tools used in dnet-hadoop
+
+ dhp-code-style
dhp-build-assembly-resources
dhp-build-properties-maven-plugin
diff --git a/dhp-common/pom.xml b/dhp-common/pom.xml
index 7b073397f0..51af8d954b 100644
--- a/dhp-common/pom.xml
+++ b/dhp-common/pom.xml
@@ -12,6 +12,8 @@
dhp-common
jar
+ This module contains common utilities meant to be used across the dnet-hadoop submodules
+
diff --git a/dhp-common/src/main/java/eu/dnetlib/collector/worker/model/ApiDescriptor.java b/dhp-common/src/main/java/eu/dnetlib/collector/worker/model/ApiDescriptor.java
index 255104eda2..bfd70e8c63 100644
--- a/dhp-common/src/main/java/eu/dnetlib/collector/worker/model/ApiDescriptor.java
+++ b/dhp-common/src/main/java/eu/dnetlib/collector/worker/model/ApiDescriptor.java
@@ -1,9 +1,9 @@
+
package eu.dnetlib.collector.worker.model;
import java.util.HashMap;
import java.util.Map;
-
public class ApiDescriptor {
private String id;
@@ -45,5 +45,4 @@ public class ApiDescriptor {
public void setProtocol(final String protocol) {
this.protocol = protocol;
}
-
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStore.java b/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStore.java
index 478bda4402..68fc024afa 100644
--- a/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStore.java
+++ b/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStore.java
@@ -1,3 +1,4 @@
+
package eu.dnetlib.data.mdstore.manager.common.model;
import java.io.Serializable;
@@ -12,9 +13,7 @@ import javax.persistence.Table;
@Table(name = "mdstores")
public class MDStore implements Serializable {
- /**
- *
- */
+ /** */
private static final long serialVersionUID = 3160530489149700055L;
@Id
@@ -95,16 +94,18 @@ public class MDStore implements Serializable {
this.apiId = apiId;
}
- public static MDStore newInstance(final String format, final String layout, final String interpretation) {
+ public static MDStore newInstance(
+ final String format, final String layout, final String interpretation) {
return newInstance(format, layout, interpretation, null, null, null);
}
- public static MDStore newInstance(final String format,
- final String layout,
- final String interpretation,
- final String dsName,
- final String dsId,
- final String apiId) {
+ public static MDStore newInstance(
+ final String format,
+ final String layout,
+ final String interpretation,
+ final String dsName,
+ final String dsId,
+ final String apiId) {
final MDStore md = new MDStore();
md.setId("md-" + UUID.randomUUID());
md.setFormat(format);
@@ -115,5 +116,4 @@ public class MDStore implements Serializable {
md.setApiId(apiId);
return md;
}
-
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreCurrentVersion.java b/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreCurrentVersion.java
index 2a52d0d1d1..f74ab39be2 100644
--- a/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreCurrentVersion.java
+++ b/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreCurrentVersion.java
@@ -1,3 +1,4 @@
+
package eu.dnetlib.data.mdstore.manager.common.model;
import java.io.Serializable;
@@ -11,9 +12,7 @@ import javax.persistence.Table;
@Table(name = "mdstore_current_versions")
public class MDStoreCurrentVersion implements Serializable {
- /**
- *
- */
+ /** */
private static final long serialVersionUID = -4757725888593745773L;
@Id
diff --git a/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreVersion.java b/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreVersion.java
index 4ad6f137c1..7ef24f1916 100644
--- a/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreVersion.java
+++ b/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreVersion.java
@@ -1,3 +1,4 @@
+
package eu.dnetlib.data.mdstore.manager.common.model;
import java.io.Serializable;
@@ -14,9 +15,7 @@ import javax.persistence.TemporalType;
@Table(name = "mdstore_versions")
public class MDStoreVersion implements Serializable {
- /**
- *
- */
+ /** */
private static final long serialVersionUID = -4763494442274298339L;
@Id
@@ -97,5 +96,4 @@ public class MDStoreVersion implements Serializable {
public void setSize(final long size) {
this.size = size;
}
-
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreWithInfo.java b/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreWithInfo.java
index dfe188f549..4383592410 100644
--- a/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreWithInfo.java
+++ b/dhp-common/src/main/java/eu/dnetlib/data/mdstore/manager/common/model/MDStoreWithInfo.java
@@ -1,3 +1,4 @@
+
package eu.dnetlib.data.mdstore.manager.common.model;
import java.io.Serializable;
@@ -14,9 +15,7 @@ import javax.persistence.TemporalType;
@Table(name = "mdstores_with_info")
public class MDStoreWithInfo implements Serializable {
- /**
- *
- */
+ /** */
private static final long serialVersionUID = -8445784770687571492L;
@Id
@@ -141,5 +140,4 @@ public class MDStoreWithInfo implements Serializable {
public void setNumberOfVersions(final long numberOfVersions) {
this.numberOfVersions = numberOfVersions;
}
-
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/application/ArgumentApplicationParser.java b/dhp-common/src/main/java/eu/dnetlib/dhp/application/ArgumentApplicationParser.java
index cbfc5caf14..e65b4bb0bf 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/application/ArgumentApplicationParser.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/application/ArgumentApplicationParser.java
@@ -1,9 +1,5 @@
-package eu.dnetlib.dhp.application;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.commons.cli.*;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.IOUtils;
+package eu.dnetlib.dhp.application;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -12,76 +8,91 @@ import java.io.StringWriter;
import java.util.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
-import java.util.zip.Inflater;
+
+import org.apache.commons.cli.*;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.IOUtils;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
public class ArgumentApplicationParser implements Serializable {
- private final Options options = new Options();
- private final Map objectMap = new HashMap<>();
+ private final Options options = new Options();
+ private final Map objectMap = new HashMap<>();
- private final List compressedValues = new ArrayList<>();
+ private final List compressedValues = new ArrayList<>();
- public ArgumentApplicationParser(final String json_configuration) throws Exception {
- final ObjectMapper mapper = new ObjectMapper();
- final OptionsParameter[] configuration = mapper.readValue(json_configuration, OptionsParameter[].class);
- createOptionMap(configuration);
- }
+ public ArgumentApplicationParser(final String json_configuration) throws Exception {
+ final ObjectMapper mapper = new ObjectMapper();
+ final OptionsParameter[] configuration = mapper.readValue(json_configuration, OptionsParameter[].class);
+ createOptionMap(configuration);
+ }
- public ArgumentApplicationParser(final OptionsParameter[] configuration) {
- createOptionMap(configuration);
- }
+ public ArgumentApplicationParser(final OptionsParameter[] configuration) {
+ createOptionMap(configuration);
+ }
- private void createOptionMap(final OptionsParameter[] configuration) {
+ private void createOptionMap(final OptionsParameter[] configuration) {
- Arrays.stream(configuration).map(conf -> {
- final Option o = new Option(conf.getParamName(), true, conf.getParamDescription());
- o.setLongOpt(conf.getParamLongName());
- o.setRequired(conf.isParamRequired());
- if (conf.isCompressed()) {
- compressedValues.add(conf.getParamLongName());
- }
- return o;
- }).forEach(options::addOption);
+ Arrays
+ .stream(configuration)
+ .map(
+ conf -> {
+ final Option o = new Option(conf.getParamName(), true, conf.getParamDescription());
+ o.setLongOpt(conf.getParamLongName());
+ o.setRequired(conf.isParamRequired());
+ if (conf.isCompressed()) {
+ compressedValues.add(conf.getParamLongName());
+ }
+ return o;
+ })
+ .forEach(options::addOption);
-// HelpFormatter formatter = new HelpFormatter();
-// formatter.printHelp("myapp", null, options, null, true);
+ // HelpFormatter formatter = new HelpFormatter();
+ // formatter.printHelp("myapp", null, options, null, true);
+ }
- }
+ public static String decompressValue(final String abstractCompressed) {
+ try {
+ byte[] byteArray = Base64.decodeBase64(abstractCompressed.getBytes());
+ GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(byteArray));
+ final StringWriter stringWriter = new StringWriter();
+ IOUtils.copy(gis, stringWriter);
+ return stringWriter.toString();
+ } catch (Throwable e) {
+ System.out.println("Wrong value to decompress:" + abstractCompressed);
+ throw new RuntimeException(e);
+ }
+ }
+ public static String compressArgument(final String value) throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ GZIPOutputStream gzip = new GZIPOutputStream(out);
+ gzip.write(value.getBytes());
+ gzip.close();
+ return java.util.Base64.getEncoder().encodeToString(out.toByteArray());
+ }
- public static String decompressValue(final String abstractCompressed) {
- try {
- byte[] byteArray = Base64.decodeBase64(abstractCompressed.getBytes());
- GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(byteArray));
- final StringWriter stringWriter = new StringWriter();
- IOUtils.copy(gis, stringWriter);
- return stringWriter.toString();
- } catch (Throwable e) {
- System.out.println("Wrong value to decompress:" + abstractCompressed);
- throw new RuntimeException(e);
- }
- }
+ public void parseArgument(final String[] args) throws Exception {
+ CommandLineParser parser = new BasicParser();
+ CommandLine cmd = parser.parse(options, args);
+ Arrays
+ .stream(cmd.getOptions())
+ .forEach(
+ it -> objectMap
+ .put(
+ it.getLongOpt(),
+ compressedValues.contains(it.getLongOpt())
+ ? decompressValue(it.getValue())
+ : it.getValue()));
+ }
- public static String compressArgument(final String value) throws Exception{
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- GZIPOutputStream gzip = new GZIPOutputStream(out);
- gzip.write(value.getBytes());
- gzip.close();
- return java.util.Base64.getEncoder().encodeToString(out.toByteArray());
- }
+ public String get(final String key) {
+ return objectMap.get(key);
+ }
- public void parseArgument(final String[] args) throws Exception {
- CommandLineParser parser = new BasicParser();
- CommandLine cmd = parser.parse(options, args);
- Arrays.stream(cmd.getOptions()).forEach(it -> objectMap.put(it.getLongOpt(), compressedValues.contains(it.getLongOpt())? decompressValue(it.getValue()): it.getValue()));
- }
-
- public String get(final String key) {
- return objectMap.get(key);
- }
-
- public Map getObjectMap() {
- return objectMap;
- }
+ public Map getObjectMap() {
+ return objectMap;
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/application/OptionsParameter.java b/dhp-common/src/main/java/eu/dnetlib/dhp/application/OptionsParameter.java
index 4e7c2826bb..7004112e42 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/application/OptionsParameter.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/application/OptionsParameter.java
@@ -1,38 +1,38 @@
-package eu.dnetlib.dhp.application;
+package eu.dnetlib.dhp.application;
public class OptionsParameter {
- private String paramName;
- private String paramLongName;
- private String paramDescription;
- private boolean paramRequired;
- private boolean compressed;
+ private String paramName;
+ private String paramLongName;
+ private String paramDescription;
+ private boolean paramRequired;
+ private boolean compressed;
- public OptionsParameter() {
- }
+ public OptionsParameter() {
+ }
- public String getParamName() {
- return paramName;
- }
+ public String getParamName() {
+ return paramName;
+ }
- public String getParamLongName() {
- return paramLongName;
- }
+ public String getParamLongName() {
+ return paramLongName;
+ }
- public String getParamDescription() {
- return paramDescription;
- }
+ public String getParamDescription() {
+ return paramDescription;
+ }
- public boolean isParamRequired() {
- return paramRequired;
- }
+ public boolean isParamRequired() {
+ return paramRequired;
+ }
- public boolean isCompressed() {
- return compressed;
- }
+ public boolean isCompressed() {
+ return compressed;
+ }
- public void setCompressed(boolean compressed) {
- this.compressed = compressed;
- }
+ public void setCompressed(boolean compressed) {
+ this.compressed = compressed;
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/common/FunctionalInterfaceSupport.java b/dhp-common/src/main/java/eu/dnetlib/dhp/common/FunctionalInterfaceSupport.java
index d78520f55b..e793e3f295 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/common/FunctionalInterfaceSupport.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/common/FunctionalInterfaceSupport.java
@@ -1,56 +1,54 @@
+
package eu.dnetlib.dhp.common;
import java.io.Serializable;
import java.util.function.Supplier;
-/**
- * Provides serializable and throwing extensions to standard functional interfaces.
- */
+/** Provides serializable and throwing extensions to standard functional interfaces. */
public class FunctionalInterfaceSupport {
- private FunctionalInterfaceSupport() {
- }
+ private FunctionalInterfaceSupport() {
+ }
- /**
- * Serializable supplier of any kind of objects. To be used withing spark processing pipelines when supplying
- * functions externally.
- *
- * @param
- */
- @FunctionalInterface
- public interface SerializableSupplier extends Supplier, Serializable {
- }
+ /**
+ * Serializable supplier of any kind of objects. To be used withing spark processing pipelines when supplying
+ * functions externally.
+ *
+ * @param
+ */
+ @FunctionalInterface
+ public interface SerializableSupplier extends Supplier, Serializable {
+ }
- /**
- * Extension of consumer accepting functions throwing an exception.
- *
- * @param
- * @param
- */
- @FunctionalInterface
- public interface ThrowingConsumer {
- void accept(T t) throws E;
- }
+ /**
+ * Extension of consumer accepting functions throwing an exception.
+ *
+ * @param
+ * @param
+ */
+ @FunctionalInterface
+ public interface ThrowingConsumer {
+ void accept(T t) throws E;
+ }
- /**
- * Extension of supplier accepting functions throwing an exception.
- *
- * @param
- * @param
- */
- @FunctionalInterface
- public interface ThrowingSupplier {
- T get() throws E;
- }
+ /**
+ * Extension of supplier accepting functions throwing an exception.
+ *
+ * @param
+ * @param
+ */
+ @FunctionalInterface
+ public interface ThrowingSupplier {
+ T get() throws E;
+ }
- /**
- * Extension of runnable accepting functions throwing an exception.
- *
- * @param
- */
- @FunctionalInterface
- public interface ThrowingRunnable {
- void run() throws E;
- }
-
-}
\ No newline at end of file
+ /**
+ * Extension of runnable accepting functions throwing an exception.
+ *
+ * @param
+ */
+ @FunctionalInterface
+ public interface ThrowingRunnable {
+ void run() throws E;
+ }
+}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/common/HdfsSupport.java b/dhp-common/src/main/java/eu/dnetlib/dhp/common/HdfsSupport.java
index 05beaa51e1..0b2cd571fa 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/common/HdfsSupport.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/common/HdfsSupport.java
@@ -1,5 +1,12 @@
+
package eu.dnetlib.dhp.common;
+import static eu.dnetlib.dhp.common.ThrowingSupport.rethrowAsRuntimeException;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
@@ -7,51 +14,61 @@ import org.apache.hadoop.fs.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import static eu.dnetlib.dhp.common.ThrowingSupport.rethrowAsRuntimeException;
-
-/**
- * HDFS utility methods.
- */
+/** HDFS utility methods. */
public class HdfsSupport {
- private static final Logger logger = LoggerFactory.getLogger(HdfsSupport.class);
+ private static final Logger logger = LoggerFactory.getLogger(HdfsSupport.class);
- private HdfsSupport() {
- }
+ private HdfsSupport() {
+ }
- /**
- * Removes a path (file or dir) from HDFS.
- *
- * @param path Path to be removed
- * @param configuration Configuration of hadoop env
- */
- public static void remove(String path, Configuration configuration) {
- logger.info("Removing path: {}", path);
- rethrowAsRuntimeException(() -> {
- Path f = new Path(path);
- FileSystem fileSystem = FileSystem.get(configuration);
- if (fileSystem.exists(f)) {
- fileSystem.delete(f, true);
- }
- });
- }
+ /**
+ * Checks a path (file or dir) exists on HDFS.
+ *
+ * @param path Path to be checked
+ * @param configuration Configuration of hadoop env
+ */
+ public static boolean exists(String path, Configuration configuration) {
+ logger.info("Removing path: {}", path);
+ return rethrowAsRuntimeException(
+ () -> {
+ Path f = new Path(path);
+ FileSystem fileSystem = FileSystem.get(configuration);
+ return fileSystem.exists(f);
+ });
+ }
- /**
- * Lists hadoop files located below path or alternatively lists subdirs under path.
- *
- * @param path Path to be listed for hadoop files
- * @param configuration Configuration of hadoop env
- * @return List with string locations of hadoop files
- */
- public static List listFiles(String path, Configuration configuration) {
- logger.info("Listing files in path: {}", path);
- return rethrowAsRuntimeException(() -> Arrays
- .stream(FileSystem.get(configuration).listStatus(new Path(path)))
- .filter(FileStatus::isDirectory)
- .map(x -> x.getPath().toString())
- .collect(Collectors.toList()));
- }
+ /**
+ * Removes a path (file or dir) from HDFS.
+ *
+ * @param path Path to be removed
+ * @param configuration Configuration of hadoop env
+ */
+ public static void remove(String path, Configuration configuration) {
+ logger.info("Removing path: {}", path);
+ rethrowAsRuntimeException(
+ () -> {
+ Path f = new Path(path);
+ FileSystem fileSystem = FileSystem.get(configuration);
+ if (fileSystem.exists(f)) {
+ fileSystem.delete(f, true);
+ }
+ });
+ }
+
+ /**
+ * Lists hadoop files located below path or alternatively lists subdirs under path.
+ *
+ * @param path Path to be listed for hadoop files
+ * @param configuration Configuration of hadoop env
+ * @return List with string locations of hadoop files
+ */
+ public static List listFiles(String path, Configuration configuration) {
+ logger.info("Listing files in path: {}", path);
+ return rethrowAsRuntimeException(
+ () -> Arrays
+ .stream(FileSystem.get(configuration).listStatus(new Path(path)))
+ .filter(FileStatus::isDirectory)
+ .map(x -> x.getPath().toString())
+ .collect(Collectors.toList()));
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/common/SparkSessionSupport.java b/dhp-common/src/main/java/eu/dnetlib/dhp/common/SparkSessionSupport.java
index 43c18a9560..03cc949615 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/common/SparkSessionSupport.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/common/SparkSessionSupport.java
@@ -1,71 +1,75 @@
-package eu.dnetlib.dhp.common;
-import eu.dnetlib.dhp.common.FunctionalInterfaceSupport.ThrowingConsumer;
-import org.apache.spark.SparkConf;
-import org.apache.spark.sql.SparkSession;
+package eu.dnetlib.dhp.common;
import java.util.Objects;
import java.util.function.Function;
-/**
- * SparkSession utility methods.
- */
+import org.apache.spark.SparkConf;
+import org.apache.spark.sql.SparkSession;
+
+import eu.dnetlib.dhp.common.FunctionalInterfaceSupport.ThrowingConsumer;
+
+/** SparkSession utility methods. */
public class SparkSessionSupport {
- private SparkSessionSupport() {
- }
+ private SparkSessionSupport() {
+ }
- /**
- * Runs a given function using SparkSession created using default builder and supplied SparkConf. Stops SparkSession
- * when SparkSession is managed. Allows to reuse SparkSession created externally.
- *
- * @param conf SparkConf instance
- * @param isSparkSessionManaged When true will stop SparkSession
- * @param fn Consumer to be applied to constructed SparkSession
- */
- public static void runWithSparkSession(SparkConf conf,
- Boolean isSparkSessionManaged,
- ThrowingConsumer fn) {
- runWithSparkSession(c -> SparkSession.builder().config(c).getOrCreate(), conf, isSparkSessionManaged, fn);
- }
+ /**
+ * Runs a given function using SparkSession created using default builder and supplied SparkConf. Stops SparkSession
+ * when SparkSession is managed. Allows to reuse SparkSession created externally.
+ *
+ * @param conf SparkConf instance
+ * @param isSparkSessionManaged When true will stop SparkSession
+ * @param fn Consumer to be applied to constructed SparkSession
+ */
+ public static void runWithSparkSession(
+ SparkConf conf, Boolean isSparkSessionManaged, ThrowingConsumer fn) {
+ runWithSparkSession(
+ c -> SparkSession.builder().config(c).getOrCreate(), conf, isSparkSessionManaged, fn);
+ }
- /**
- * Runs a given function using SparkSession created with hive support and using default builder and supplied SparkConf.
- * Stops SparkSession when SparkSession is managed. Allows to reuse SparkSession created externally.
- *
- * @param conf SparkConf instance
- * @param isSparkSessionManaged When true will stop SparkSession
- * @param fn Consumer to be applied to constructed SparkSession
- */
- public static void runWithSparkHiveSession(SparkConf conf,
- Boolean isSparkSessionManaged,
- ThrowingConsumer fn) {
- runWithSparkSession(c -> SparkSession.builder().config(c).enableHiveSupport().getOrCreate(), conf, isSparkSessionManaged, fn);
- }
+ /**
+ * Runs a given function using SparkSession created with hive support and using default builder and supplied
+ * SparkConf. Stops SparkSession when SparkSession is managed. Allows to reuse SparkSession created externally.
+ *
+ * @param conf SparkConf instance
+ * @param isSparkSessionManaged When true will stop SparkSession
+ * @param fn Consumer to be applied to constructed SparkSession
+ */
+ public static void runWithSparkHiveSession(
+ SparkConf conf, Boolean isSparkSessionManaged, ThrowingConsumer fn) {
+ runWithSparkSession(
+ c -> SparkSession.builder().config(c).enableHiveSupport().getOrCreate(),
+ conf,
+ isSparkSessionManaged,
+ fn);
+ }
- /**
- * Runs a given function using SparkSession created using supplied builder and supplied SparkConf. Stops SparkSession
- * when SparkSession is managed. Allows to reuse SparkSession created externally.
- *
- * @param sparkSessionBuilder Builder of SparkSession
- * @param conf SparkConf instance
- * @param isSparkSessionManaged When true will stop SparkSession
- * @param fn Consumer to be applied to constructed SparkSession
- */
- public static void runWithSparkSession(Function sparkSessionBuilder,
- SparkConf conf,
- Boolean isSparkSessionManaged,
- ThrowingConsumer fn) {
- SparkSession spark = null;
- try {
- spark = sparkSessionBuilder.apply(conf);
- fn.accept(spark);
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (Objects.nonNull(spark) && isSparkSessionManaged) {
- spark.stop();
- }
- }
- }
-}
\ No newline at end of file
+ /**
+ * Runs a given function using SparkSession created using supplied builder and supplied SparkConf. Stops
+ * SparkSession when SparkSession is managed. Allows to reuse SparkSession created externally.
+ *
+ * @param sparkSessionBuilder Builder of SparkSession
+ * @param conf SparkConf instance
+ * @param isSparkSessionManaged When true will stop SparkSession
+ * @param fn Consumer to be applied to constructed SparkSession
+ */
+ public static void runWithSparkSession(
+ Function sparkSessionBuilder,
+ SparkConf conf,
+ Boolean isSparkSessionManaged,
+ ThrowingConsumer fn) {
+ SparkSession spark = null;
+ try {
+ spark = sparkSessionBuilder.apply(conf);
+ fn.accept(spark);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (Objects.nonNull(spark) && isSparkSessionManaged) {
+ spark.stop();
+ }
+ }
+ }
+}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/common/ThrowingSupport.java b/dhp-common/src/main/java/eu/dnetlib/dhp/common/ThrowingSupport.java
index b32803c378..f3f59b2a21 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/common/ThrowingSupport.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/common/ThrowingSupport.java
@@ -1,76 +1,76 @@
+
package eu.dnetlib.dhp.common;
import eu.dnetlib.dhp.common.FunctionalInterfaceSupport.ThrowingRunnable;
import eu.dnetlib.dhp.common.FunctionalInterfaceSupport.ThrowingSupplier;
-/**
- * Exception handling utility methods.
- */
+/** Exception handling utility methods. */
public class ThrowingSupport {
- private ThrowingSupport() {
- }
+ private ThrowingSupport() {
+ }
- /**
- * Executes given runnable and rethrows any exceptions as RuntimeException.
- *
- * @param fn Runnable to be executed
- * @param Type of exception thrown
- */
- public static void rethrowAsRuntimeException(ThrowingRunnable fn) {
- try {
- fn.run();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
+ /**
+ * Executes given runnable and rethrows any exceptions as RuntimeException.
+ *
+ * @param fn Runnable to be executed
+ * @param Type of exception thrown
+ */
+ public static void rethrowAsRuntimeException(ThrowingRunnable fn) {
+ try {
+ fn.run();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
- /**
- * Executes given runnable and rethrows any exceptions as RuntimeException with custom message.
- *
- * @param fn Runnable to be executed
- * @param msg Message to be set for rethrown exception
- * @param Type of exception thrown
- */
- public static void rethrowAsRuntimeException(ThrowingRunnable fn, String msg) {
- try {
- fn.run();
- } catch (Exception e) {
- throw new RuntimeException(msg, e);
- }
- }
+ /**
+ * Executes given runnable and rethrows any exceptions as RuntimeException with custom message.
+ *
+ * @param fn Runnable to be executed
+ * @param msg Message to be set for rethrown exception
+ * @param Type of exception thrown
+ */
+ public static void rethrowAsRuntimeException(
+ ThrowingRunnable fn, String msg) {
+ try {
+ fn.run();
+ } catch (Exception e) {
+ throw new RuntimeException(msg, e);
+ }
+ }
- /**
- * Executes given supplier and rethrows any exceptions as RuntimeException.
- *
- * @param fn Supplier to be executed
- * @param Type of returned value
- * @param Type of exception thrown
- * @return Result of supplier execution
- */
- public static T rethrowAsRuntimeException(ThrowingSupplier fn) {
- try {
- return fn.get();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
+ /**
+ * Executes given supplier and rethrows any exceptions as RuntimeException.
+ *
+ * @param fn Supplier to be executed
+ * @param Type of returned value
+ * @param Type of exception thrown
+ * @return Result of supplier execution
+ */
+ public static T rethrowAsRuntimeException(ThrowingSupplier fn) {
+ try {
+ return fn.get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
- /**
- * Executes given supplier and rethrows any exceptions as RuntimeException with custom message.
- *
- * @param fn Supplier to be executed
- * @param msg Message to be set for rethrown exception
- * @param Type of returned value
- * @param Type of exception thrown
- * @return Result of supplier execution
- */
- public static T rethrowAsRuntimeException(ThrowingSupplier fn, String msg) {
- try {
- return fn.get();
- } catch (Exception e) {
- throw new RuntimeException(msg, e);
- }
- }
-
-}
\ No newline at end of file
+ /**
+ * Executes given supplier and rethrows any exceptions as RuntimeException with custom message.
+ *
+ * @param fn Supplier to be executed
+ * @param msg Message to be set for rethrown exception
+ * @param Type of returned value
+ * @param Type of exception thrown
+ * @return Result of supplier execution
+ */
+ public static T rethrowAsRuntimeException(
+ ThrowingSupplier fn, String msg) {
+ try {
+ return fn.get();
+ } catch (Exception e) {
+ throw new RuntimeException(msg, e);
+ }
+ }
+}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/model/mdstore/MetadataRecord.java b/dhp-common/src/main/java/eu/dnetlib/dhp/model/mdstore/MetadataRecord.java
index acbb7ffbbb..ce65e710f9 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/model/mdstore/MetadataRecord.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/model/mdstore/MetadataRecord.java
@@ -1,137 +1,121 @@
-package eu.dnetlib.dhp.model.mdstore;
-import eu.dnetlib.dhp.utils.DHPUtils;
+package eu.dnetlib.dhp.model.mdstore;
import java.io.Serializable;
+import eu.dnetlib.dhp.utils.DHPUtils;
-/**
- * This class models a record inside the new Metadata store collection on HDFS *
- *
- */
+/** This class models a record inside the new Metadata store collection on HDFS * */
public class MetadataRecord implements Serializable {
- /**
- * The D-Net Identifier associated to the record
- */
- private String id;
+ /** The D-Net Identifier associated to the record */
+ private String id;
- /**
- * The original Identifier of the record
- */
- private String originalId;
+ /** The original Identifier of the record */
+ private String originalId;
+ /** The encoding of the record, should be JSON or XML */
+ private String encoding;
- /**
- * The encoding of the record, should be JSON or XML
- */
- private String encoding;
+ /**
+ * The information about the provenance of the record see @{@link Provenance} for the model of this information
+ */
+ private Provenance provenance;
- /**
- * The information about the provenance of the record see @{@link Provenance}
- * for the model of this information
- */
- private Provenance provenance;
+ /** The content of the metadata */
+ private String body;
- /**
- * The content of the metadata
- */
- private String body;
+ /** the date when the record has been stored */
+ private long dateOfCollection;
- /**
- * the date when the record has been stored
- */
- private long dateOfCollection;
+ /** the date when the record has been stored */
+ private long dateOfTransformation;
- /**
- * the date when the record has been stored
- */
- private long dateOfTransformation;
+ public MetadataRecord() {
+ this.dateOfCollection = System.currentTimeMillis();
+ }
+ public MetadataRecord(
+ String originalId,
+ String encoding,
+ Provenance provenance,
+ String body,
+ long dateOfCollection) {
- public MetadataRecord() {
- this.dateOfCollection = System.currentTimeMillis();
- }
+ this.originalId = originalId;
+ this.encoding = encoding;
+ this.provenance = provenance;
+ this.body = body;
+ this.dateOfCollection = dateOfCollection;
+ this.id = DHPUtils.generateIdentifier(originalId, this.provenance.getNsPrefix());
+ }
- public MetadataRecord(String originalId, String encoding, Provenance provenance, String body, long dateOfCollection) {
+ public String getId() {
+ return id;
+ }
- this.originalId = originalId;
- this.encoding = encoding;
- this.provenance = provenance;
- this.body = body;
- this.dateOfCollection = dateOfCollection;
- this.id = DHPUtils.generateIdentifier(originalId,this.provenance.getNsPrefix());
- }
+ public void setId(String id) {
+ this.id = id;
+ }
- public String getId() {
- return id;
- }
+ public String getOriginalId() {
+ return originalId;
+ }
- public void setId(String id) {
- this.id = id;
- }
+ public void setOriginalId(String originalId) {
+ this.originalId = originalId;
+ }
+ public String getEncoding() {
+ return encoding;
+ }
- public String getOriginalId() {
- return originalId;
- }
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
- public void setOriginalId(String originalId) {
- this.originalId = originalId;
- }
+ public Provenance getProvenance() {
+ return provenance;
+ }
- public String getEncoding() {
- return encoding;
- }
+ public void setProvenance(Provenance provenance) {
+ this.provenance = provenance;
+ }
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
+ public String getBody() {
+ return body;
+ }
- public Provenance getProvenance() {
- return provenance;
- }
+ public void setBody(String body) {
+ this.body = body;
+ }
- public void setProvenance(Provenance provenance) {
- this.provenance = provenance;
- }
+ public long getDateOfCollection() {
+ return dateOfCollection;
+ }
+ public void setDateOfCollection(long dateOfCollection) {
+ this.dateOfCollection = dateOfCollection;
+ }
- public String getBody() {
- return body;
- }
+ public long getDateOfTransformation() {
+ return dateOfTransformation;
+ }
- public void setBody(String body) {
- this.body = body;
- }
+ public void setDateOfTransformation(long dateOfTransformation) {
+ this.dateOfTransformation = dateOfTransformation;
+ }
- public long getDateOfCollection() {
- return dateOfCollection;
- }
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof MetadataRecord)) {
+ return false;
+ }
+ return ((MetadataRecord) o).getId().equalsIgnoreCase(id);
+ }
- public void setDateOfCollection(long dateOfCollection) {
- this.dateOfCollection = dateOfCollection;
- }
-
- public long getDateOfTransformation() {
- return dateOfTransformation;
- }
-
- public void setDateOfTransformation(long dateOfTransformation) {
- this.dateOfTransformation = dateOfTransformation;
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof MetadataRecord)) {
- return false;
- }
- return ((MetadataRecord) o).getId().equalsIgnoreCase(id);
-
- }
-
- @Override
- public int hashCode() {
- return id.hashCode();
- }
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/model/mdstore/Provenance.java b/dhp-common/src/main/java/eu/dnetlib/dhp/model/mdstore/Provenance.java
index de67281f23..556535022e 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/model/mdstore/Provenance.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/model/mdstore/Provenance.java
@@ -1,56 +1,52 @@
+
package eu.dnetlib.dhp.model.mdstore;
import java.io.Serializable;
-
/**
* @author Sandro La Bruzzo
- *
- * Provenace class models the provenance of the record in the metadataStore
- * It contains the identifier and the name of the datasource that gives the
- * record
- *
+ *
+ * Provenace class models the provenance of the record in the metadataStore It contains the identifier and the
+ * name of the datasource that gives the record
*/
public class Provenance implements Serializable {
- private String datasourceId;
+ private String datasourceId;
+ private String datasourceName;
- private String datasourceName;
+ private String nsPrefix;
- private String nsPrefix;
+ public Provenance() {
+ }
- public Provenance() {
+ public Provenance(String datasourceId, String datasourceName, String nsPrefix) {
+ this.datasourceId = datasourceId;
+ this.datasourceName = datasourceName;
+ this.nsPrefix = nsPrefix;
+ }
- }
+ public String getDatasourceId() {
+ return datasourceId;
+ }
- public Provenance(String datasourceId, String datasourceName, String nsPrefix) {
- this.datasourceId = datasourceId;
- this.datasourceName = datasourceName;
- this.nsPrefix = nsPrefix;
- }
+ public void setDatasourceId(String datasourceId) {
+ this.datasourceId = datasourceId;
+ }
- public String getDatasourceId() {
- return datasourceId;
- }
+ public String getDatasourceName() {
+ return datasourceName;
+ }
- public void setDatasourceId(String datasourceId) {
- this.datasourceId = datasourceId;
- }
+ public void setDatasourceName(String datasourceName) {
+ this.datasourceName = datasourceName;
+ }
- public String getDatasourceName() {
- return datasourceName;
- }
+ public String getNsPrefix() {
+ return nsPrefix;
+ }
- public void setDatasourceName(String datasourceName) {
- this.datasourceName = datasourceName;
- }
-
- public String getNsPrefix() {
- return nsPrefix;
- }
-
- public void setNsPrefix(String nsPrefix) {
- this.nsPrefix = nsPrefix;
- }
+ public void setNsPrefix(String nsPrefix) {
+ this.nsPrefix = nsPrefix;
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/parser/utility/VtdException.java b/dhp-common/src/main/java/eu/dnetlib/dhp/parser/utility/VtdException.java
index 77b28f207f..22945309c0 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/parser/utility/VtdException.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/parser/utility/VtdException.java
@@ -1,12 +1,13 @@
+
package eu.dnetlib.dhp.parser.utility;
public class VtdException extends Exception {
- public VtdException(final Exception e) {
- super(e);
- }
+ public VtdException(final Exception e) {
+ super(e);
+ }
- public VtdException(final Throwable e) {
- super(e);
- }
-}
\ No newline at end of file
+ public VtdException(final Throwable e) {
+ super(e);
+ }
+}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/parser/utility/VtdUtilityParser.java b/dhp-common/src/main/java/eu/dnetlib/dhp/parser/utility/VtdUtilityParser.java
index 5d92e1c5fd..9ac0a0bf71 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/parser/utility/VtdUtilityParser.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/parser/utility/VtdUtilityParser.java
@@ -1,3 +1,4 @@
+
package eu.dnetlib.dhp.parser.utility;
import java.util.ArrayList;
@@ -5,103 +6,105 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import com.ximpleware.AutoPilot;
import com.ximpleware.VTDNav;
-/**
- * Created by sandro on 9/29/16.
- */
+/** Created by sandro on 9/29/16. */
public class VtdUtilityParser {
- public static List getTextValuesWithAttributes(final AutoPilot ap, final VTDNav vn, final String xpath, final List attributes)
- throws VtdException {
- final List results = new ArrayList<>();
- try {
- ap.selectXPath(xpath);
+ public static List getTextValuesWithAttributes(
+ final AutoPilot ap, final VTDNav vn, final String xpath, final List attributes)
+ throws VtdException {
+ final List results = new ArrayList<>();
+ try {
+ ap.selectXPath(xpath);
- while (ap.evalXPath() != -1) {
- final Node currentNode = new Node();
- int t = vn.getText();
- if (t >= 0) {
- currentNode.setTextValue(vn.toNormalizedString(t));
- }
- currentNode.setAttributes(getAttributes(vn, attributes));
- results.add(currentNode);
- }
- return results;
- } catch (Exception e) {
- throw new VtdException(e);
- }
- }
+ while (ap.evalXPath() != -1) {
+ final Node currentNode = new Node();
+ int t = vn.getText();
+ if (t >= 0) {
+ currentNode.setTextValue(vn.toNormalizedString(t));
+ }
+ currentNode.setAttributes(getAttributes(vn, attributes));
+ results.add(currentNode);
+ }
+ return results;
+ } catch (Exception e) {
+ throw new VtdException(e);
+ }
+ }
- private static Map getAttributes(final VTDNav vn, final List attributes) {
- final Map currentAttributes = new HashMap<>();
- if (attributes != null) {
+ private static Map getAttributes(final VTDNav vn, final List attributes) {
+ final Map currentAttributes = new HashMap<>();
+ if (attributes != null) {
- attributes.forEach(attributeKey -> {
- try {
- int attr = vn.getAttrVal(attributeKey);
- if (attr > -1) {
- currentAttributes.put(attributeKey, vn.toNormalizedString(attr));
- }
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- });
- }
- return currentAttributes;
- }
+ attributes
+ .forEach(
+ attributeKey -> {
+ try {
+ int attr = vn.getAttrVal(attributeKey);
+ if (attr > -1) {
+ currentAttributes.put(attributeKey, vn.toNormalizedString(attr));
+ }
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ });
+ }
+ return currentAttributes;
+ }
- public static List getTextValue(final AutoPilot ap, final VTDNav vn, final String xpath) throws VtdException {
- List results = new ArrayList<>();
- try {
- ap.selectXPath(xpath);
- while (ap.evalXPath() != -1) {
- int t = vn.getText();
- if (t > -1) results.add(vn.toNormalizedString(t));
- }
- return results;
- } catch (Exception e) {
- throw new VtdException(e);
- }
- }
+ public static List getTextValue(final AutoPilot ap, final VTDNav vn, final String xpath)
+ throws VtdException {
+ List results = new ArrayList<>();
+ try {
+ ap.selectXPath(xpath);
+ while (ap.evalXPath() != -1) {
+ int t = vn.getText();
+ if (t > -1)
+ results.add(vn.toNormalizedString(t));
+ }
+ return results;
+ } catch (Exception e) {
+ throw new VtdException(e);
+ }
+ }
- public static String getSingleValue(final AutoPilot ap, final VTDNav nav, final String xpath) throws VtdException {
- try {
- ap.selectXPath(xpath);
- while (ap.evalXPath() != -1) {
- int it = nav.getText();
- if (it > -1)
- return nav.toNormalizedString(it);
- }
- return null;
- } catch (Exception e) {
- throw new VtdException(e);
- }
- }
+ public static String getSingleValue(final AutoPilot ap, final VTDNav nav, final String xpath)
+ throws VtdException {
+ try {
+ ap.selectXPath(xpath);
+ while (ap.evalXPath() != -1) {
+ int it = nav.getText();
+ if (it > -1)
+ return nav.toNormalizedString(it);
+ }
+ return null;
+ } catch (Exception e) {
+ throw new VtdException(e);
+ }
+ }
- public static class Node {
+ public static class Node {
- private String textValue;
+ private String textValue;
- private Map attributes;
+ private Map attributes;
- public String getTextValue() {
- return textValue;
- }
+ public String getTextValue() {
+ return textValue;
+ }
- public void setTextValue(final String textValue) {
- this.textValue = textValue;
- }
+ public void setTextValue(final String textValue) {
+ this.textValue = textValue;
+ }
- public Map getAttributes() {
- return attributes;
- }
-
- public void setAttributes(final Map attributes) {
- this.attributes = attributes;
- }
- }
+ public Map getAttributes() {
+ return attributes;
+ }
+ public void setAttributes(final Map attributes) {
+ this.attributes = attributes;
+ }
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/DHPUtils.java b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/DHPUtils.java
index ea8943efd2..dfbaf3a6ca 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/DHPUtils.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/DHPUtils.java
@@ -1,11 +1,5 @@
-package eu.dnetlib.dhp.utils;
-import com.jayway.jsonpath.JsonPath;
-import net.minidev.json.JSONArray;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Base64OutputStream;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.lang3.StringUtils;
+package eu.dnetlib.dhp.utils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -14,61 +8,68 @@ import java.security.MessageDigest;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Base64OutputStream;
+import org.apache.commons.codec.binary.Hex;
+
+import com.jayway.jsonpath.JsonPath;
+
+import net.minidev.json.JSONArray;
+
public class DHPUtils {
- public static String md5(final String s) {
- try {
- final MessageDigest md = MessageDigest.getInstance("MD5");
- md.update(s.getBytes("UTF-8"));
- return new String(Hex.encodeHex(md.digest()));
- } catch (final Exception e) {
- System.err.println("Error creating id");
- return null;
- }
- }
+ public static String md5(final String s) {
+ try {
+ final MessageDigest md = MessageDigest.getInstance("MD5");
+ md.update(s.getBytes(StandardCharsets.UTF_8));
+ return new String(Hex.encodeHex(md.digest()));
+ } catch (final Exception e) {
+ System.err.println("Error creating id");
+ return null;
+ }
+ }
- public static String generateIdentifier(final String originalId, final String nsPrefix) {
- return String.format("%s::%s",nsPrefix, DHPUtils.md5(originalId));
- }
+ public static String generateIdentifier(final String originalId, final String nsPrefix) {
+ return String.format("%s::%s", nsPrefix, DHPUtils.md5(originalId));
+ }
- public static String compressString(final String input ) {
- try ( ByteArrayOutputStream out = new ByteArrayOutputStream(); Base64OutputStream b64os = new Base64OutputStream(out)) {
- GZIPOutputStream gzip = new GZIPOutputStream(b64os);
- gzip.write(input.getBytes(StandardCharsets.UTF_8));
- gzip.close();
- return out.toString();
- } catch (Throwable e ) {
- return null;
- }
- }
+ public static String compressString(final String input) {
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream();
+ Base64OutputStream b64os = new Base64OutputStream(out)) {
+ GZIPOutputStream gzip = new GZIPOutputStream(b64os);
+ gzip.write(input.getBytes(StandardCharsets.UTF_8));
+ gzip.close();
+ return out.toString();
+ } catch (Throwable e) {
+ return null;
+ }
+ }
+ public static String decompressString(final String input) {
+ byte[] byteArray = Base64.decodeBase64(input.getBytes());
+ int len;
+ try (GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream((byteArray)));
+ ByteArrayOutputStream bos = new ByteArrayOutputStream(byteArray.length)) {
+ byte[] buffer = new byte[1024];
+ while ((len = gis.read(buffer)) != -1) {
+ bos.write(buffer, 0, len);
+ }
+ return bos.toString();
+ } catch (Exception e) {
+ return null;
+ }
+ }
- public static String decompressString(final String input) {
- byte[] byteArray = Base64.decodeBase64(input.getBytes());
- int len;
- try (GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream((byteArray))); ByteArrayOutputStream bos = new ByteArrayOutputStream(byteArray.length)) {
- byte[] buffer = new byte[1024];
- while((len = gis.read(buffer)) != -1){
- bos.write(buffer, 0, len);
- }
- return bos.toString();
- } catch (Exception e) {
- return null;
- }
-
- }
-
- public static String getJPathString(final String jsonPath, final String json) {
- try {
- Object o = JsonPath.read(json, jsonPath);
- if (o instanceof String)
- return (String) o;
- if (o instanceof JSONArray && ((JSONArray) o).size() > 0)
- return (String) ((JSONArray) o).get(0);
- return o.toString();
- } catch (Exception e) {
- return "";
- }
- }
-
+ public static String getJPathString(final String jsonPath, final String json) {
+ try {
+ Object o = JsonPath.read(json, jsonPath);
+ if (o instanceof String)
+ return (String) o;
+ if (o instanceof JSONArray && ((JSONArray) o).size() > 0)
+ return (String) ((JSONArray) o).get(0);
+ return o.toString();
+ } catch (Exception e) {
+ return "";
+ }
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/ISLookupClientFactory.java b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/ISLookupClientFactory.java
index c74cf3c111..97fe4b9d83 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/ISLookupClientFactory.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/ISLookupClientFactory.java
@@ -1,24 +1,26 @@
+
package eu.dnetlib.dhp.utils;
-import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
+
public class ISLookupClientFactory {
- private static final Log log = LogFactory.getLog(ISLookupClientFactory.class);
+ private static final Log log = LogFactory.getLog(ISLookupClientFactory.class);
- public static ISLookUpService getLookUpService(final String isLookupUrl) {
- return getServiceStub(ISLookUpService.class, isLookupUrl);
- }
+ public static ISLookUpService getLookUpService(final String isLookupUrl) {
+ return getServiceStub(ISLookUpService.class, isLookupUrl);
+ }
- @SuppressWarnings("unchecked")
- private static T getServiceStub(final Class clazz, final String endpoint) {
- log.info(String.format("creating %s stub from %s", clazz.getName(), endpoint));
- final JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean();
- jaxWsProxyFactory.setServiceClass(clazz);
- jaxWsProxyFactory.setAddress(endpoint);
- return (T) jaxWsProxyFactory.create();
- }
+ @SuppressWarnings("unchecked")
+ private static T getServiceStub(final Class clazz, final String endpoint) {
+ log.info(String.format("creating %s stub from %s", clazz.getName(), endpoint));
+ final JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean();
+ jaxWsProxyFactory.setServiceClass(clazz);
+ jaxWsProxyFactory.setAddress(endpoint);
+ return (T) jaxWsProxyFactory.create();
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/AbstractExtensionFunction.java b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/AbstractExtensionFunction.java
index bd39624404..9b00b908c1 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/AbstractExtensionFunction.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/AbstractExtensionFunction.java
@@ -1,3 +1,4 @@
+
package eu.dnetlib.dhp.utils.saxon;
import net.sf.saxon.expr.XPathContext;
@@ -9,24 +10,24 @@ import net.sf.saxon.trans.XPathException;
public abstract class AbstractExtensionFunction extends ExtensionFunctionDefinition {
- public static String DEFAULT_SAXON_EXT_NS_URI = "http://www.d-net.research-infrastructures.eu/saxon-extension";
+ public static String DEFAULT_SAXON_EXT_NS_URI = "http://www.d-net.research-infrastructures.eu/saxon-extension";
- public abstract String getName();
- public abstract Sequence doCall(XPathContext context, Sequence[] arguments) throws XPathException;
+ public abstract String getName();
- @Override
- public StructuredQName getFunctionQName() {
- return new StructuredQName("dnet", DEFAULT_SAXON_EXT_NS_URI, getName());
- }
+ public abstract Sequence doCall(XPathContext context, Sequence[] arguments) throws XPathException;
- @Override
- public ExtensionFunctionCall makeCallExpression() {
- return new ExtensionFunctionCall() {
- @Override
- public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
- return doCall(context, arguments);
- }
- };
- }
+ @Override
+ public StructuredQName getFunctionQName() {
+ return new StructuredQName("dnet", DEFAULT_SAXON_EXT_NS_URI, getName());
+ }
-}
\ No newline at end of file
+ @Override
+ public ExtensionFunctionCall makeCallExpression() {
+ return new ExtensionFunctionCall() {
+ @Override
+ public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
+ return doCall(context, arguments);
+ }
+ };
+ }
+}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/ExtractYear.java b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/ExtractYear.java
index f90e2a23e8..c7e311b02a 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/ExtractYear.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/ExtractYear.java
@@ -1,5 +1,11 @@
+
package eu.dnetlib.dhp.utils.saxon;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.Sequence;
@@ -7,61 +13,61 @@ import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.SequenceType;
import net.sf.saxon.value.StringValue;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-
public class ExtractYear extends AbstractExtensionFunction {
- private static final String[] dateFormats = { "yyyy-MM-dd", "yyyy/MM/dd" };
+ private static final String[] dateFormats = {
+ "yyyy-MM-dd", "yyyy/MM/dd"
+ };
- @Override
- public String getName() {
- return "extractYear";
- }
+ @Override
+ public String getName() {
+ return "extractYear";
+ }
- @Override
- public Sequence doCall(XPathContext context, Sequence[] arguments) throws XPathException {
- if (arguments == null | arguments.length == 0) {
- return new StringValue("");
- }
- final Item item = arguments[0].head();
- if (item == null) {
- return new StringValue("");
- }
- return new StringValue(_year(item.getStringValue()));
- }
+ @Override
+ public Sequence doCall(XPathContext context, Sequence[] arguments) throws XPathException {
+ if (arguments == null | arguments.length == 0) {
+ return new StringValue("");
+ }
+ final Item item = arguments[0].head();
+ if (item == null) {
+ return new StringValue("");
+ }
+ return new StringValue(_year(item.getStringValue()));
+ }
- @Override
- public int getMinimumNumberOfArguments() {
- return 0;
- }
+ @Override
+ public int getMinimumNumberOfArguments() {
+ return 0;
+ }
- @Override
- public int getMaximumNumberOfArguments() {
- return 1;
- }
+ @Override
+ public int getMaximumNumberOfArguments() {
+ return 1;
+ }
- @Override
- public SequenceType[] getArgumentTypes() {
- return new SequenceType[] { SequenceType.OPTIONAL_ITEM };
- }
+ @Override
+ public SequenceType[] getArgumentTypes() {
+ return new SequenceType[] {
+ SequenceType.OPTIONAL_ITEM
+ };
+ }
- @Override
- public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
- return SequenceType.SINGLE_STRING;
- }
+ @Override
+ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
+ return SequenceType.SINGLE_STRING;
+ }
- private String _year(String s) {
- Calendar c = new GregorianCalendar();
- for (String format : dateFormats) {
- try {
- c.setTime(new SimpleDateFormat(format).parse(s));
- String year = String.valueOf(c.get(Calendar.YEAR));
- return year;
- } catch (ParseException e) {}
- }
- return "";
- }
+ private String _year(String s) {
+ Calendar c = new GregorianCalendar();
+ for (String format : dateFormats) {
+ try {
+ c.setTime(new SimpleDateFormat(format).parse(s));
+ String year = String.valueOf(c.get(Calendar.YEAR));
+ return year;
+ } catch (ParseException e) {
+ }
+ }
+ return "";
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/NormalizeDate.java b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/NormalizeDate.java
index 634e08788b..9fb60e1452 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/NormalizeDate.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/NormalizeDate.java
@@ -1,66 +1,71 @@
+
package eu.dnetlib.dhp.utils.saxon;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.SequenceType;
import net.sf.saxon.value.StringValue;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
public class NormalizeDate extends AbstractExtensionFunction {
- private static final String[] normalizeDateFormats = { "yyyy-MM-dd'T'hh:mm:ss", "yyyy-MM-dd", "yyyy/MM/dd", "yyyy" };
+ private static final String[] normalizeDateFormats = {
+ "yyyy-MM-dd'T'hh:mm:ss", "yyyy-MM-dd", "yyyy/MM/dd", "yyyy"
+ };
- private static final String normalizeOutFormat = new String("yyyy-MM-dd'T'hh:mm:ss'Z'");
+ private static final String normalizeOutFormat = "yyyy-MM-dd'T'hh:mm:ss'Z'";
- @Override
- public String getName() {
- return "normalizeDate";
- }
+ @Override
+ public String getName() {
+ return "normalizeDate";
+ }
- @Override
- public Sequence doCall(XPathContext context, Sequence[] arguments) throws XPathException {
- if (arguments == null | arguments.length == 0) {
- return new StringValue("");
- }
- String s = arguments[0].head().getStringValue();
- return new StringValue(_year(s));
- }
+ @Override
+ public Sequence doCall(XPathContext context, Sequence[] arguments) throws XPathException {
+ if (arguments == null | arguments.length == 0) {
+ return new StringValue("");
+ }
+ String s = arguments[0].head().getStringValue();
+ return new StringValue(_year(s));
+ }
- @Override
- public int getMinimumNumberOfArguments() {
- return 0;
- }
+ @Override
+ public int getMinimumNumberOfArguments() {
+ return 0;
+ }
- @Override
- public int getMaximumNumberOfArguments() {
- return 1;
- }
+ @Override
+ public int getMaximumNumberOfArguments() {
+ return 1;
+ }
- @Override
- public SequenceType[] getArgumentTypes() {
- return new SequenceType[] { SequenceType.OPTIONAL_ITEM };
- }
+ @Override
+ public SequenceType[] getArgumentTypes() {
+ return new SequenceType[] {
+ SequenceType.OPTIONAL_ITEM
+ };
+ }
- @Override
- public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
- return SequenceType.SINGLE_STRING;
- }
+ @Override
+ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
+ return SequenceType.SINGLE_STRING;
+ }
- private String _year(String s) {
- final String date = s != null ? s.trim() : "";
-
- for (String format : normalizeDateFormats) {
- try {
- Date parse = new SimpleDateFormat(format).parse(date);
- String res = new SimpleDateFormat(normalizeOutFormat).format(parse);
- return res;
- } catch (ParseException e) {}
- }
- return "";
- }
+ private String _year(String s) {
+ final String date = s != null ? s.trim() : "";
+ for (String format : normalizeDateFormats) {
+ try {
+ Date parse = new SimpleDateFormat(format).parse(date);
+ String res = new SimpleDateFormat(normalizeOutFormat).format(parse);
+ return res;
+ } catch (ParseException e) {
+ }
+ }
+ return "";
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/PickFirst.java b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/PickFirst.java
index a221e37c67..46ecafd0aa 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/PickFirst.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/PickFirst.java
@@ -1,60 +1,63 @@
+
package eu.dnetlib.dhp.utils.saxon;
+import org.apache.commons.lang3.StringUtils;
+
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.SequenceType;
import net.sf.saxon.value.StringValue;
-import org.apache.commons.lang3.StringUtils;
public class PickFirst extends AbstractExtensionFunction {
- @Override
- public String getName() {
- return "pickFirst";
- }
+ @Override
+ public String getName() {
+ return "pickFirst";
+ }
- @Override
- public Sequence doCall(XPathContext context, Sequence[] arguments) throws XPathException {
- if (arguments == null | arguments.length == 0) {
- return new StringValue("");
- }
+ @Override
+ public Sequence doCall(XPathContext context, Sequence[] arguments) throws XPathException {
+ if (arguments == null | arguments.length == 0) {
+ return new StringValue("");
+ }
- final String s1 = getValue(arguments[0]);
- final String s2 = getValue(arguments[1]);
+ final String s1 = getValue(arguments[0]);
+ final String s2 = getValue(arguments[1]);
- return new StringValue(StringUtils.isNotBlank(s1) ? s1 : StringUtils.isNotBlank(s2) ? s2 : "");
- }
+ return new StringValue(StringUtils.isNotBlank(s1) ? s1 : StringUtils.isNotBlank(s2) ? s2 : "");
+ }
- private String getValue(final Sequence arg) throws XPathException {
- if (arg != null) {
- final Item item = arg.head();
- if (item != null) {
- return item.getStringValue();
- }
- }
- return "";
- }
+ private String getValue(final Sequence arg) throws XPathException {
+ if (arg != null) {
+ final Item item = arg.head();
+ if (item != null) {
+ return item.getStringValue();
+ }
+ }
+ return "";
+ }
- @Override
- public int getMinimumNumberOfArguments() {
- return 0;
- }
+ @Override
+ public int getMinimumNumberOfArguments() {
+ return 0;
+ }
- @Override
- public int getMaximumNumberOfArguments() {
- return 2;
- }
+ @Override
+ public int getMaximumNumberOfArguments() {
+ return 2;
+ }
- @Override
- public SequenceType[] getArgumentTypes() {
- return new SequenceType[] { SequenceType.OPTIONAL_ITEM };
- }
-
- @Override
- public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
- return SequenceType.SINGLE_STRING;
- }
+ @Override
+ public SequenceType[] getArgumentTypes() {
+ return new SequenceType[] {
+ SequenceType.OPTIONAL_ITEM
+ };
+ }
+ @Override
+ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
+ return SequenceType.SINGLE_STRING;
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/SaxonTransformerFactory.java b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/SaxonTransformerFactory.java
index 611709ff0d..b85d866f11 100644
--- a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/SaxonTransformerFactory.java
+++ b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/SaxonTransformerFactory.java
@@ -1,30 +1,32 @@
+
package eu.dnetlib.dhp.utils.saxon;
-import net.sf.saxon.Configuration;
-import net.sf.saxon.TransformerFactoryImpl;
+import java.io.StringReader;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
-import java.io.StringReader;
+
+import net.sf.saxon.Configuration;
+import net.sf.saxon.TransformerFactoryImpl;
public class SaxonTransformerFactory {
- /**
- * Creates the index record transformer from the given XSLT
- * @param xslt
- * @return
- * @throws TransformerException
- */
- public static Transformer newInstance(final String xslt) throws TransformerException {
+ /**
+ * Creates the index record transformer from the given XSLT
+ *
+ * @param xslt
+ * @return
+ * @throws TransformerException
+ */
+ public static Transformer newInstance(final String xslt) throws TransformerException {
- final TransformerFactoryImpl factory = new TransformerFactoryImpl();
- final Configuration conf = factory.getConfiguration();
- conf.registerExtensionFunction(new ExtractYear());
- conf.registerExtensionFunction(new NormalizeDate());
- conf.registerExtensionFunction(new PickFirst());
-
- return factory.newTransformer(new StreamSource(new StringReader(xslt)));
- }
+ final TransformerFactoryImpl factory = new TransformerFactoryImpl();
+ final Configuration conf = factory.getConfiguration();
+ conf.registerExtensionFunction(new ExtractYear());
+ conf.registerExtensionFunction(new NormalizeDate());
+ conf.registerExtensionFunction(new PickFirst());
+ return factory.newTransformer(new StreamSource(new StringReader(xslt)));
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/message/Message.java b/dhp-common/src/main/java/eu/dnetlib/message/Message.java
index 3767bd0260..fc1c382910 100644
--- a/dhp-common/src/main/java/eu/dnetlib/message/Message.java
+++ b/dhp-common/src/main/java/eu/dnetlib/message/Message.java
@@ -1,82 +1,76 @@
-package eu.dnetlib.message;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+package eu.dnetlib.message;
import java.io.IOException;
import java.util.Map;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
public class Message {
- private String workflowId;
+ private String workflowId;
- private String jobName;
+ private String jobName;
- private MessageType type;
+ private MessageType type;
- private Map body;
+ private Map body;
+ public static Message fromJson(final String json) throws IOException {
+ final ObjectMapper jsonMapper = new ObjectMapper();
+ return jsonMapper.readValue(json, Message.class);
+ }
- public static Message fromJson(final String json) throws IOException {
- final ObjectMapper jsonMapper = new ObjectMapper();
- return jsonMapper.readValue(json, Message.class);
+ public Message() {
+ }
+ public Message(String workflowId, String jobName, MessageType type, Map body) {
+ this.workflowId = workflowId;
+ this.jobName = jobName;
+ this.type = type;
+ this.body = body;
+ }
- }
+ public String getWorkflowId() {
+ return workflowId;
+ }
+ public void setWorkflowId(String workflowId) {
+ this.workflowId = workflowId;
+ }
- public Message() {
+ public String getJobName() {
+ return jobName;
+ }
+ public void setJobName(String jobName) {
+ this.jobName = jobName;
+ }
+ public MessageType getType() {
+ return type;
+ }
- }
+ public void setType(MessageType type) {
+ this.type = type;
+ }
- public Message(String workflowId, String jobName, MessageType type, Map body) {
- this.workflowId = workflowId;
- this.jobName = jobName;
- this.type = type;
- this.body = body;
- }
+ public Map getBody() {
+ return body;
+ }
- public String getWorkflowId() {
- return workflowId;
- }
+ public void setBody(Map body) {
+ this.body = body;
+ }
- public void setWorkflowId(String workflowId) {
- this.workflowId = workflowId;
- }
-
- public String getJobName() {
- return jobName;
- }
-
- public void setJobName(String jobName) {
- this.jobName = jobName;
- }
-
- public MessageType getType() {
- return type;
- }
-
- public void setType(MessageType type) {
- this.type = type;
- }
-
- public Map getBody() {
- return body;
- }
-
- public void setBody(Map body) {
- this.body = body;
- }
-
- @Override
- public String toString() {
- final ObjectMapper jsonMapper = new ObjectMapper();
- try {
- return jsonMapper.writeValueAsString(this);
- } catch (JsonProcessingException e) {
- return null;
- }
- }
+ @Override
+ public String toString() {
+ final ObjectMapper jsonMapper = new ObjectMapper();
+ try {
+ return jsonMapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ return null;
+ }
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/message/MessageConsumer.java b/dhp-common/src/main/java/eu/dnetlib/message/MessageConsumer.java
index af5339034d..fb3f0bd956 100644
--- a/dhp-common/src/main/java/eu/dnetlib/message/MessageConsumer.java
+++ b/dhp-common/src/main/java/eu/dnetlib/message/MessageConsumer.java
@@ -1,46 +1,47 @@
+
package eu.dnetlib.message;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.LinkedBlockingQueue;
+
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.concurrent.LinkedBlockingQueue;
-
public class MessageConsumer extends DefaultConsumer {
- final LinkedBlockingQueue queueMessages;
+ final LinkedBlockingQueue queueMessages;
+ /**
+ * Constructs a new instance and records its association to the passed-in channel.
+ *
+ * @param channel the channel to which this consumer is attached
+ * @param queueMessages
+ */
+ public MessageConsumer(Channel channel, LinkedBlockingQueue queueMessages) {
+ super(channel);
+ this.queueMessages = queueMessages;
+ }
- /**
- * Constructs a new instance and records its association to the passed-in channel.
- *
- * @param channel the channel to which this consumer is attached
- * @param queueMessages
- */
- public MessageConsumer(Channel channel, LinkedBlockingQueue queueMessages) {
- super(channel);
- this.queueMessages = queueMessages;
- }
-
-
- @Override
- public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
- final String json = new String(body, StandardCharsets.UTF_8);
- Message message = Message.fromJson(json);
- try {
- this.queueMessages.put(message);
- System.out.println("Receiving Message "+message);
- } catch (InterruptedException e) {
- if (message.getType()== MessageType.REPORT)
- throw new RuntimeException("Error on sending message");
- else {
- //TODO LOGGING EXCEPTION
- }
- } finally {
- getChannel().basicAck(envelope.getDeliveryTag(), false);
- }
- }
+ @Override
+ public void handleDelivery(
+ String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
+ throws IOException {
+ final String json = new String(body, StandardCharsets.UTF_8);
+ Message message = Message.fromJson(json);
+ try {
+ this.queueMessages.put(message);
+ System.out.println("Receiving Message " + message);
+ } catch (InterruptedException e) {
+ if (message.getType() == MessageType.REPORT)
+ throw new RuntimeException("Error on sending message");
+ else {
+ // TODO LOGGING EXCEPTION
+ }
+ } finally {
+ getChannel().basicAck(envelope.getDeliveryTag(), false);
+ }
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/message/MessageManager.java b/dhp-common/src/main/java/eu/dnetlib/message/MessageManager.java
index e3d90f7e0e..5ca79f3cc6 100644
--- a/dhp-common/src/main/java/eu/dnetlib/message/MessageManager.java
+++ b/dhp-common/src/main/java/eu/dnetlib/message/MessageManager.java
@@ -1,9 +1,5 @@
-package eu.dnetlib.message;
-import com.rabbitmq.client.Channel;
-import com.rabbitmq.client.Connection;
-import com.rabbitmq.client.ConnectionFactory;
-import sun.rmi.runtime.Log;
+package eu.dnetlib.message;
import java.io.IOException;
import java.util.HashMap;
@@ -11,107 +7,130 @@ import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeoutException;
+import com.rabbitmq.client.Channel;
+import com.rabbitmq.client.Connection;
+import com.rabbitmq.client.ConnectionFactory;
+
public class MessageManager {
- private final String messageHost;
+ private final String messageHost;
- private final String username;
+ private final String username;
- private final String password;
+ private final String password;
- private Connection connection;
+ private Connection connection;
- private Map channels = new HashMap<>();
+ private final Map channels = new HashMap<>();
- private boolean durable;
+ private boolean durable;
- private boolean autodelete;
+ private boolean autodelete;
- final private LinkedBlockingQueue queueMessages;
+ private final LinkedBlockingQueue queueMessages;
- public MessageManager(String messageHost, String username, String password, final LinkedBlockingQueue queueMessages) {
- this.queueMessages = queueMessages;
- this.messageHost = messageHost;
- this.username = username;
- this.password = password;
- }
+ public MessageManager(
+ String messageHost,
+ String username,
+ String password,
+ final LinkedBlockingQueue queueMessages) {
+ this.queueMessages = queueMessages;
+ this.messageHost = messageHost;
+ this.username = username;
+ this.password = password;
+ }
+ public MessageManager(
+ String messageHost,
+ String username,
+ String password,
+ boolean durable,
+ boolean autodelete,
+ final LinkedBlockingQueue queueMessages) {
+ this.queueMessages = queueMessages;
+ this.messageHost = messageHost;
+ this.username = username;
+ this.password = password;
- public MessageManager(String messageHost, String username, String password, boolean durable, boolean autodelete, final LinkedBlockingQueue queueMessages) {
- this.queueMessages = queueMessages;
- this.messageHost = messageHost;
- this.username = username;
- this.password = password;
+ this.durable = durable;
+ this.autodelete = autodelete;
+ }
- this.durable = durable;
- this.autodelete = autodelete;
- }
+ private Connection createConnection() throws IOException, TimeoutException {
+ ConnectionFactory factory = new ConnectionFactory();
+ factory.setHost(this.messageHost);
+ factory.setUsername(this.username);
+ factory.setPassword(this.password);
+ return factory.newConnection();
+ }
- private Connection createConnection() throws IOException, TimeoutException {
- ConnectionFactory factory = new ConnectionFactory();
- factory.setHost(this.messageHost);
- factory.setUsername(this.username);
- factory.setPassword(this.password);
- return factory.newConnection();
- }
+ private Channel createChannel(
+ final Connection connection,
+ final String queueName,
+ final boolean durable,
+ final boolean autodelete)
+ throws Exception {
+ Map args = new HashMap<>();
+ args.put("x-message-ttl", 10000);
+ Channel channel = connection.createChannel();
+ channel.queueDeclare(queueName, durable, false, this.autodelete, args);
+ return channel;
+ }
- private Channel createChannel(final Connection connection, final String queueName, final boolean durable, final boolean autodelete ) throws Exception {
- Map args = new HashMap<>();
- args.put("x-message-ttl", 10000);
- Channel channel = connection.createChannel();
- channel.queueDeclare(queueName, durable, false, this.autodelete, args);
- return channel;
- }
+ private Channel getOrCreateChannel(final String queueName, boolean durable, boolean autodelete)
+ throws Exception {
+ if (channels.containsKey(queueName)) {
+ return channels.get(queueName);
+ }
- private Channel getOrCreateChannel(final String queueName, boolean durable, boolean autodelete) throws Exception {
- if (channels.containsKey(queueName)) {
- return channels.get(queueName);
- }
+ if (this.connection == null) {
+ this.connection = createConnection();
+ }
+ channels.put(queueName, createChannel(this.connection, queueName, durable, autodelete));
+ return channels.get(queueName);
+ }
- if (this.connection == null) {
- this.connection = createConnection();
- }
- channels.put(queueName, createChannel(this.connection, queueName, durable, autodelete));
- return channels.get(queueName);
- }
+ public void close() throws IOException {
+ channels
+ .values()
+ .forEach(
+ ch -> {
+ try {
+ ch.close();
+ } catch (Exception e) {
+ // TODO LOG
+ }
+ });
+ this.connection.close();
+ }
+ public boolean sendMessage(final Message message, String queueName) throws Exception {
+ try {
+ Channel channel = getOrCreateChannel(queueName, this.durable, this.autodelete);
+ channel.basicPublish("", queueName, null, message.toString().getBytes());
+ return true;
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
- public void close() throws IOException {
- channels.values().forEach(ch-> {
- try {
- ch.close();
- } catch (Exception e) {
- //TODO LOG
- }
- });
+ public boolean sendMessage(
+ final Message message, String queueName, boolean durable_var, boolean autodelete_var)
+ throws Exception {
+ try {
+ Channel channel = getOrCreateChannel(queueName, durable_var, autodelete_var);
+ channel.basicPublish("", queueName, null, message.toString().getBytes());
+ return true;
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
- this.connection.close();
- }
+ public void startConsumingMessage(
+ final String queueName, final boolean durable, final boolean autodelete) throws Exception {
- public boolean sendMessage(final Message message, String queueName) throws Exception {
- try {
- Channel channel = getOrCreateChannel(queueName, this.durable, this.autodelete);
- channel.basicPublish("", queueName,null, message.toString().getBytes());
- return true;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- public boolean sendMessage(final Message message, String queueName, boolean durable_var, boolean autodelete_var) throws Exception {
- try {
- Channel channel = getOrCreateChannel(queueName, durable_var, autodelete_var);
- channel.basicPublish("", queueName,null, message.toString().getBytes());
- return true;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- public void startConsumingMessage(final String queueName, final boolean durable, final boolean autodelete) throws Exception{
-
- Channel channel = createChannel(createConnection(), queueName, durable, autodelete);
- channel.basicConsume(queueName, false, new MessageConsumer(channel,queueMessages));
- }
+ Channel channel = createChannel(createConnection(), queueName, durable, autodelete);
+ channel.basicConsume(queueName, false, new MessageConsumer(channel, queueMessages));
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/message/MessageType.java b/dhp-common/src/main/java/eu/dnetlib/message/MessageType.java
index c2440c3fe7..72cbda2528 100644
--- a/dhp-common/src/main/java/eu/dnetlib/message/MessageType.java
+++ b/dhp-common/src/main/java/eu/dnetlib/message/MessageType.java
@@ -1,8 +1,6 @@
+
package eu.dnetlib.message;
public enum MessageType {
-
- ONGOING,
- REPORT
-
+ ONGOING, REPORT
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/scholexplorer/relation/RelInfo.java b/dhp-common/src/main/java/eu/dnetlib/scholexplorer/relation/RelInfo.java
index ff88cda4c1..e07fcef66e 100644
--- a/dhp-common/src/main/java/eu/dnetlib/scholexplorer/relation/RelInfo.java
+++ b/dhp-common/src/main/java/eu/dnetlib/scholexplorer/relation/RelInfo.java
@@ -1,24 +1,25 @@
+
package eu.dnetlib.scholexplorer.relation;
import java.io.Serializable;
-public class RelInfo implements Serializable {
- private String original;
- private String inverse;
+public class RelInfo implements Serializable {
+ private String original;
+ private String inverse;
- public String getOriginal() {
- return original;
- }
+ public String getOriginal() {
+ return original;
+ }
- public void setOriginal(String original) {
- this.original = original;
- }
+ public void setOriginal(String original) {
+ this.original = original;
+ }
- public String getInverse() {
- return inverse;
- }
+ public String getInverse() {
+ return inverse;
+ }
- public void setInverse(String inverse) {
- this.inverse = inverse;
- }
+ public void setInverse(String inverse) {
+ this.inverse = inverse;
+ }
}
diff --git a/dhp-common/src/main/java/eu/dnetlib/scholexplorer/relation/RelationMapper.java b/dhp-common/src/main/java/eu/dnetlib/scholexplorer/relation/RelationMapper.java
index 647c117896..eb708c390c 100644
--- a/dhp-common/src/main/java/eu/dnetlib/scholexplorer/relation/RelationMapper.java
+++ b/dhp-common/src/main/java/eu/dnetlib/scholexplorer/relation/RelationMapper.java
@@ -1,19 +1,20 @@
-package eu.dnetlib.scholexplorer.relation;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.commons.io.IOUtils;
+package eu.dnetlib.scholexplorer.relation;
import java.io.Serializable;
import java.util.HashMap;
-public class RelationMapper extends HashMap implements Serializable {
+import org.apache.commons.io.IOUtils;
- public static RelationMapper load() throws Exception {
+import com.fasterxml.jackson.databind.ObjectMapper;
- final String json = IOUtils.toString(RelationMapper.class.getResourceAsStream("relations.json"));
+public class RelationMapper extends HashMap implements Serializable {
- ObjectMapper mapper = new ObjectMapper();
- return mapper.readValue(json, RelationMapper.class);
- }
+ public static RelationMapper load() throws Exception {
+ final String json = IOUtils.toString(RelationMapper.class.getResourceAsStream("relations.json"));
+
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.readValue(json, RelationMapper.class);
+ }
}
diff --git a/dhp-common/src/test/java/eu/dnetlib/dhp/application/ArgumentApplicationParserTest.java b/dhp-common/src/test/java/eu/dnetlib/dhp/application/ArgumentApplicationParserTest.java
index f4598ebd49..e140208308 100644
--- a/dhp-common/src/test/java/eu/dnetlib/dhp/application/ArgumentApplicationParserTest.java
+++ b/dhp-common/src/test/java/eu/dnetlib/dhp/application/ArgumentApplicationParserTest.java
@@ -1,56 +1,67 @@
-package eu.dnetlib.dhp.application;
-import org.apache.commons.io.IOUtils;
-import org.junit.jupiter.api.Test;
+package eu.dnetlib.dhp.application;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import org.apache.commons.io.IOUtils;
+import org.junit.jupiter.api.Test;
+
public class ArgumentApplicationParserTest {
- @Test
- public void testParseParameter() throws Exception {
- final String jsonConfiguration = IOUtils.toString(this.getClass().getResourceAsStream("/eu/dnetlib/application/parameters.json"));
- assertNotNull(jsonConfiguration);
- ArgumentApplicationParser parser = new ArgumentApplicationParser(jsonConfiguration);
- parser.parseArgument(new String[]{"-p", "value0",
- "-a", "value1",
- "-n", "value2",
- "-u", "value3",
- "-ru", "value4",
- "-rp", "value5",
- "-rh", "value6",
- "-ro", "value7",
- "-rr", "value8",
- "-w", "value9",
- "-cc", ArgumentApplicationParser.compressArgument(jsonConfiguration)
- });
- assertNotNull(parser.get("hdfsPath"));
- assertNotNull(parser.get("apidescriptor"));
- assertNotNull(parser.get("namenode"));
- assertNotNull(parser.get("userHDFS"));
- assertNotNull(parser.get("rabbitUser"));
- assertNotNull(parser.get("rabbitPassWord"));
- assertNotNull(parser.get("rabbitHost"));
- assertNotNull(parser.get("rabbitOngoingQueue"));
- assertNotNull(parser.get("rabbitReportQueue"));
- assertNotNull(parser.get("workflowId"));
- assertEquals("value0", parser.get("hdfsPath"));
- assertEquals("value1", parser.get("apidescriptor"));
- assertEquals("value2", parser.get("namenode"));
- assertEquals("value3", parser.get("userHDFS"));
- assertEquals("value4", parser.get("rabbitUser"));
- assertEquals("value5", parser.get("rabbitPassWord"));
- assertEquals("value6", parser.get("rabbitHost"));
- assertEquals("value7", parser.get("rabbitOngoingQueue"));
- assertEquals("value8", parser.get("rabbitReportQueue"));
- assertEquals("value9", parser.get("workflowId"));
- assertEquals(jsonConfiguration, parser.get("ccCoco"));
- }
-
-
-
-
-
-
+ @Test
+ public void testParseParameter() throws Exception {
+ final String jsonConfiguration = IOUtils
+ .toString(
+ this.getClass().getResourceAsStream("/eu/dnetlib/application/parameters.json"));
+ assertNotNull(jsonConfiguration);
+ ArgumentApplicationParser parser = new ArgumentApplicationParser(jsonConfiguration);
+ parser
+ .parseArgument(
+ new String[] {
+ "-p",
+ "value0",
+ "-a",
+ "value1",
+ "-n",
+ "value2",
+ "-u",
+ "value3",
+ "-ru",
+ "value4",
+ "-rp",
+ "value5",
+ "-rh",
+ "value6",
+ "-ro",
+ "value7",
+ "-rr",
+ "value8",
+ "-w",
+ "value9",
+ "-cc",
+ ArgumentApplicationParser.compressArgument(jsonConfiguration)
+ });
+ assertNotNull(parser.get("hdfsPath"));
+ assertNotNull(parser.get("apidescriptor"));
+ assertNotNull(parser.get("namenode"));
+ assertNotNull(parser.get("userHDFS"));
+ assertNotNull(parser.get("rabbitUser"));
+ assertNotNull(parser.get("rabbitPassWord"));
+ assertNotNull(parser.get("rabbitHost"));
+ assertNotNull(parser.get("rabbitOngoingQueue"));
+ assertNotNull(parser.get("rabbitReportQueue"));
+ assertNotNull(parser.get("workflowId"));
+ assertEquals("value0", parser.get("hdfsPath"));
+ assertEquals("value1", parser.get("apidescriptor"));
+ assertEquals("value2", parser.get("namenode"));
+ assertEquals("value3", parser.get("userHDFS"));
+ assertEquals("value4", parser.get("rabbitUser"));
+ assertEquals("value5", parser.get("rabbitPassWord"));
+ assertEquals("value6", parser.get("rabbitHost"));
+ assertEquals("value7", parser.get("rabbitOngoingQueue"));
+ assertEquals("value8", parser.get("rabbitReportQueue"));
+ assertEquals("value9", parser.get("workflowId"));
+ assertEquals(jsonConfiguration, parser.get("ccCoco"));
+ }
}
diff --git a/dhp-common/src/test/java/eu/dnetlib/dhp/common/HdfsSupportTest.java b/dhp-common/src/test/java/eu/dnetlib/dhp/common/HdfsSupportTest.java
index f1e790ee7c..870943816f 100644
--- a/dhp-common/src/test/java/eu/dnetlib/dhp/common/HdfsSupportTest.java
+++ b/dhp-common/src/test/java/eu/dnetlib/dhp/common/HdfsSupportTest.java
@@ -1,9 +1,7 @@
+
package eu.dnetlib.dhp.common;
-import org.apache.hadoop.conf.Configuration;
-import org.junit.jupiter.api.Nested;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
+import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.nio.file.Files;
@@ -12,67 +10,71 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
-import static org.junit.jupiter.api.Assertions.*;
+import org.apache.hadoop.conf.Configuration;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
public class HdfsSupportTest {
- @Nested
- class Remove {
+ @Nested
+ class Remove {
- @Test
- public void shouldThrowARuntimeExceptionOnError() {
- // when
- assertThrows(RuntimeException.class, () ->
- HdfsSupport.remove(null, new Configuration()));
- }
+ @Test
+ public void shouldThrowARuntimeExceptionOnError() {
+ // when
+ assertThrows(RuntimeException.class, () -> HdfsSupport.remove(null, new Configuration()));
+ }
- @Test
- public void shouldRemoveADirFromHDFS(@TempDir Path tempDir) {
- // when
- HdfsSupport.remove(tempDir.toString(), new Configuration());
+ @Test
+ public void shouldRemoveADirFromHDFS(@TempDir Path tempDir) {
+ // when
+ HdfsSupport.remove(tempDir.toString(), new Configuration());
- // then
- assertFalse(Files.exists(tempDir));
- }
+ // then
+ assertFalse(Files.exists(tempDir));
+ }
- @Test
- public void shouldRemoveAFileFromHDFS(@TempDir Path tempDir) throws IOException {
- // given
- Path file = Files.createTempFile(tempDir, "p", "s");
+ @Test
+ public void shouldRemoveAFileFromHDFS(@TempDir Path tempDir) throws IOException {
+ // given
+ Path file = Files.createTempFile(tempDir, "p", "s");
- // when
- HdfsSupport.remove(file.toString(), new Configuration());
+ // when
+ HdfsSupport.remove(file.toString(), new Configuration());
- // then
- assertFalse(Files.exists(file));
- }
- }
+ // then
+ assertFalse(Files.exists(file));
+ }
+ }
- @Nested
- class ListFiles {
+ @Nested
+ class ListFiles {
- @Test
- public void shouldThrowARuntimeExceptionOnError() {
- // when
- assertThrows(RuntimeException.class, () ->
- HdfsSupport.listFiles(null, new Configuration()));
- }
+ @Test
+ public void shouldThrowARuntimeExceptionOnError() {
+ // when
+ assertThrows(RuntimeException.class, () -> HdfsSupport.listFiles(null, new Configuration()));
+ }
- @Test
- public void shouldListFilesLocatedInPath(@TempDir Path tempDir) throws IOException {
- Path subDir1 = Files.createTempDirectory(tempDir, "list_me");
- Path subDir2 = Files.createTempDirectory(tempDir, "list_me");
+ @Test
+ public void shouldListFilesLocatedInPath(@TempDir Path tempDir) throws IOException {
+ Path subDir1 = Files.createTempDirectory(tempDir, "list_me");
+ Path subDir2 = Files.createTempDirectory(tempDir, "list_me");
- // when
- List paths = HdfsSupport.listFiles(tempDir.toString(), new Configuration());
+ // when
+ List paths = HdfsSupport.listFiles(tempDir.toString(), new Configuration());
- // then
- assertEquals(2, paths.size());
- List expecteds = Arrays.stream(new String[]{subDir1.toString(), subDir2.toString()})
- .sorted().collect(Collectors.toList());
- List actuals = paths.stream().sorted().collect(Collectors.toList());
- assertTrue(actuals.get(0).contains(expecteds.get(0)));
- assertTrue(actuals.get(1).contains(expecteds.get(1)));
- }
- }
-}
\ No newline at end of file
+ // then
+ assertEquals(2, paths.size());
+ List expecteds = Arrays.stream(new String[] {
+ subDir1.toString(), subDir2.toString()
+ })
+ .sorted()
+ .collect(Collectors.toList());
+ List actuals = paths.stream().sorted().collect(Collectors.toList());
+ assertTrue(actuals.get(0).contains(expecteds.get(0)));
+ assertTrue(actuals.get(1).contains(expecteds.get(1)));
+ }
+ }
+}
diff --git a/dhp-common/src/test/java/eu/dnetlib/dhp/common/SparkSessionSupportTest.java b/dhp-common/src/test/java/eu/dnetlib/dhp/common/SparkSessionSupportTest.java
index bc2dce3cff..2f01c08631 100644
--- a/dhp-common/src/test/java/eu/dnetlib/dhp/common/SparkSessionSupportTest.java
+++ b/dhp-common/src/test/java/eu/dnetlib/dhp/common/SparkSessionSupportTest.java
@@ -1,54 +1,58 @@
+
package eu.dnetlib.dhp.common;
-import eu.dnetlib.dhp.common.FunctionalInterfaceSupport.ThrowingConsumer;
+import static org.mockito.Mockito.*;
+
+import java.util.function.Function;
+
import org.apache.spark.SparkConf;
import org.apache.spark.sql.SparkSession;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
-import java.util.function.Function;
-
-import static org.mockito.Mockito.*;
+import eu.dnetlib.dhp.common.FunctionalInterfaceSupport.ThrowingConsumer;
public class SparkSessionSupportTest {
- @Nested
- class RunWithSparkSession {
+ @Nested
+ class RunWithSparkSession {
- @Test
- public void shouldExecuteFunctionAndNotStopSparkSessionWhenSparkSessionIsNotManaged() throws Exception {
- // given
- SparkSession spark = mock(SparkSession.class);
- SparkConf conf = mock(SparkConf.class);
- Function sparkSessionBuilder = mock(Function.class);
- when(sparkSessionBuilder.apply(conf)).thenReturn(spark);
- ThrowingConsumer fn = mock(ThrowingConsumer.class);
+ @Test
+ public void shouldExecuteFunctionAndNotStopSparkSessionWhenSparkSessionIsNotManaged()
+ throws Exception {
+ // given
+ SparkSession spark = mock(SparkSession.class);
+ SparkConf conf = mock(SparkConf.class);
+ Function sparkSessionBuilder = mock(Function.class);
+ when(sparkSessionBuilder.apply(conf)).thenReturn(spark);
+ ThrowingConsumer fn = mock(ThrowingConsumer.class);
- // when
- SparkSessionSupport.runWithSparkSession(sparkSessionBuilder, conf, false, fn);
+ // when
+ SparkSessionSupport.runWithSparkSession(sparkSessionBuilder, conf, false, fn);
- // then
- verify(sparkSessionBuilder).apply(conf);
- verify(fn).accept(spark);
- verify(spark, never()).stop();
- }
+ // then
+ verify(sparkSessionBuilder).apply(conf);
+ verify(fn).accept(spark);
+ verify(spark, never()).stop();
+ }
- @Test
- public void shouldExecuteFunctionAndStopSparkSessionWhenSparkSessionIsManaged() throws Exception {
- // given
- SparkSession spark = mock(SparkSession.class);
- SparkConf conf = mock(SparkConf.class);
- Function sparkSessionBuilder = mock(Function.class);
- when(sparkSessionBuilder.apply(conf)).thenReturn(spark);
- ThrowingConsumer fn = mock(ThrowingConsumer.class);
+ @Test
+ public void shouldExecuteFunctionAndStopSparkSessionWhenSparkSessionIsManaged()
+ throws Exception {
+ // given
+ SparkSession spark = mock(SparkSession.class);
+ SparkConf conf = mock(SparkConf.class);
+ Function sparkSessionBuilder = mock(Function.class);
+ when(sparkSessionBuilder.apply(conf)).thenReturn(spark);
+ ThrowingConsumer fn = mock(ThrowingConsumer.class);
- // when
- SparkSessionSupport.runWithSparkSession(sparkSessionBuilder, conf, true, fn);
+ // when
+ SparkSessionSupport.runWithSparkSession(sparkSessionBuilder, conf, true, fn);
- // then
- verify(sparkSessionBuilder).apply(conf);
- verify(fn).accept(spark);
- verify(spark, times(1)).stop();
- }
- }
-}
\ No newline at end of file
+ // then
+ verify(sparkSessionBuilder).apply(conf);
+ verify(fn).accept(spark);
+ verify(spark, times(1)).stop();
+ }
+ }
+}
diff --git a/dhp-common/src/test/java/eu/dnetlib/dhp/model/mdstore/MetadataRecordTest.java b/dhp-common/src/test/java/eu/dnetlib/dhp/model/mdstore/MetadataRecordTest.java
index a2bac54baf..cb4d0ab500 100644
--- a/dhp-common/src/test/java/eu/dnetlib/dhp/model/mdstore/MetadataRecordTest.java
+++ b/dhp-common/src/test/java/eu/dnetlib/dhp/model/mdstore/MetadataRecordTest.java
@@ -1,15 +1,16 @@
-package eu.dnetlib.dhp.model.mdstore;
-import org.junit.jupiter.api.Test;
+package eu.dnetlib.dhp.model.mdstore;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+
public class MetadataRecordTest {
- @Test
- public void getTimestamp() {
+ @Test
+ public void getTimestamp() {
- MetadataRecord r = new MetadataRecord();
- assertTrue(r.getDateOfCollection() > 0);
- }
-}
\ No newline at end of file
+ MetadataRecord r = new MetadataRecord();
+ assertTrue(r.getDateOfCollection() > 0);
+ }
+}
diff --git a/dhp-common/src/test/java/eu/dnetlib/message/MessageTest.java b/dhp-common/src/test/java/eu/dnetlib/message/MessageTest.java
index 73df63b321..442f7b5c25 100644
--- a/dhp-common/src/test/java/eu/dnetlib/message/MessageTest.java
+++ b/dhp-common/src/test/java/eu/dnetlib/message/MessageTest.java
@@ -1,55 +1,51 @@
+
package eu.dnetlib.message;
-import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Test;
public class MessageTest {
- @Test
- public void fromJsonTest() throws IOException {
- Message m = new Message();
- m.setWorkflowId("wId");
- m.setType(MessageType.ONGOING);
- m.setJobName("Collection");
- Map body= new HashMap<>();
- body.put("parsedItem", "300");
- body.put("ExecutionTime", "30s");
+ @Test
+ public void fromJsonTest() throws IOException {
+ Message m = new Message();
+ m.setWorkflowId("wId");
+ m.setType(MessageType.ONGOING);
+ m.setJobName("Collection");
+ Map body = new HashMap<>();
+ body.put("parsedItem", "300");
+ body.put("ExecutionTime", "30s");
- m.setBody(body);
- System.out.println("m = " + m);
- Message m1 = Message.fromJson(m.toString());
- assertEquals(m1.getWorkflowId(), m.getWorkflowId());
- assertEquals(m1.getType(), m.getType());
- assertEquals(m1.getJobName(), m.getJobName());
+ m.setBody(body);
+ System.out.println("m = " + m);
+ Message m1 = Message.fromJson(m.toString());
+ assertEquals(m1.getWorkflowId(), m.getWorkflowId());
+ assertEquals(m1.getType(), m.getType());
+ assertEquals(m1.getJobName(), m.getJobName());
- assertNotNull(m1.getBody());
- m1.getBody().keySet().forEach(it -> assertEquals(m1.getBody().get(it), m.getBody().get(it)));
- assertEquals(m1.getJobName(), m.getJobName());
- }
+ assertNotNull(m1.getBody());
+ m1.getBody().keySet().forEach(it -> assertEquals(m1.getBody().get(it), m.getBody().get(it)));
+ assertEquals(m1.getJobName(), m.getJobName());
+ }
- @Test
- public void toStringTest() {
- final String expectedJson= "{\"workflowId\":\"wId\",\"jobName\":\"Collection\",\"type\":\"ONGOING\",\"body\":{\"ExecutionTime\":\"30s\",\"parsedItem\":\"300\"}}";
- Message m = new Message();
- m.setWorkflowId("wId");
- m.setType(MessageType.ONGOING);
- m.setJobName("Collection");
- Map body= new HashMap<>();
- body.put("parsedItem", "300");
- body.put("ExecutionTime", "30s");
+ @Test
+ public void toStringTest() {
+ final String expectedJson = "{\"workflowId\":\"wId\",\"jobName\":\"Collection\",\"type\":\"ONGOING\",\"body\":{\"ExecutionTime\":\"30s\",\"parsedItem\":\"300\"}}";
+ Message m = new Message();
+ m.setWorkflowId("wId");
+ m.setType(MessageType.ONGOING);
+ m.setJobName("Collection");
+ Map body = new HashMap<>();
+ body.put("parsedItem", "300");
+ body.put("ExecutionTime", "30s");
- m.setBody(body);
+ m.setBody(body);
- assertEquals(expectedJson,m.toString());
-
-
- }
-
-
-
-}
\ No newline at end of file
+ assertEquals(expectedJson, m.toString());
+ }
+}
diff --git a/dhp-common/src/test/java/eu/dnetlib/scholexplorer/relation/RelationMapperTest.java b/dhp-common/src/test/java/eu/dnetlib/scholexplorer/relation/RelationMapperTest.java
index eb9fb172d6..d1d1ada71a 100644
--- a/dhp-common/src/test/java/eu/dnetlib/scholexplorer/relation/RelationMapperTest.java
+++ b/dhp-common/src/test/java/eu/dnetlib/scholexplorer/relation/RelationMapperTest.java
@@ -1,15 +1,14 @@
+
package eu.dnetlib.scholexplorer.relation;
import org.junit.jupiter.api.Test;
-
public class RelationMapperTest {
- @Test
- public void testLoadRels() throws Exception{
+ @Test
+ public void testLoadRels() throws Exception {
- RelationMapper relationMapper = RelationMapper.load();
- relationMapper.keySet().forEach(System.out::println);
-
- }
+ RelationMapper relationMapper = RelationMapper.load();
+ relationMapper.keySet().forEach(System.out::println);
+ }
}
diff --git a/dhp-schemas/pom.xml b/dhp-schemas/pom.xml
index 8deb2eab23..4a123cedad 100644
--- a/dhp-schemas/pom.xml
+++ b/dhp-schemas/pom.xml
@@ -12,7 +12,7 @@
dhp-schemas
jar
-
+ This module contains common schema classes meant to be used across the dnet-hadoop submodules
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/action/AtomicAction.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/action/AtomicAction.java
index 0f9aa3adbc..84b22c81c0 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/action/AtomicAction.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/action/AtomicAction.java
@@ -1,38 +1,40 @@
+
package eu.dnetlib.dhp.schema.action;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import eu.dnetlib.dhp.schema.oaf.Oaf;
-
import java.io.Serializable;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+
+import eu.dnetlib.dhp.schema.oaf.Oaf;
+
@JsonDeserialize(using = AtomicActionDeserializer.class)
public class AtomicAction implements Serializable {
- private Class clazz;
+ private Class clazz;
- private T payload;
+ private T payload;
- public AtomicAction() {
- }
+ public AtomicAction() {
+ }
- public AtomicAction(Class clazz, T payload) {
- this.clazz = clazz;
- this.payload = payload;
- }
+ public AtomicAction(Class clazz, T payload) {
+ this.clazz = clazz;
+ this.payload = payload;
+ }
- public Class getClazz() {
- return clazz;
- }
+ public Class getClazz() {
+ return clazz;
+ }
- public void setClazz(Class clazz) {
- this.clazz = clazz;
- }
+ public void setClazz(Class clazz) {
+ this.clazz = clazz;
+ }
- public T getPayload() {
- return payload;
- }
+ public T getPayload() {
+ return payload;
+ }
- public void setPayload(T payload) {
- this.payload = payload;
- }
+ public void setPayload(T payload) {
+ this.payload = payload;
+ }
}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/action/AtomicActionDeserializer.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/action/AtomicActionDeserializer.java
index e6017288fa..7b88e9c7eb 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/action/AtomicActionDeserializer.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/action/AtomicActionDeserializer.java
@@ -1,29 +1,32 @@
+
package eu.dnetlib.dhp.schema.action;
+import java.io.IOException;
+
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import eu.dnetlib.dhp.schema.oaf.Oaf;
-import java.io.IOException;
+import eu.dnetlib.dhp.schema.oaf.Oaf;
public class AtomicActionDeserializer extends JsonDeserializer {
- @Override
- public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
- JsonNode node = jp.getCodec().readTree(jp);
- String classTag = node.get("clazz").asText();
- JsonNode payload = node.get("payload");
- ObjectMapper mapper = new ObjectMapper();
+ @Override
+ public Object deserialize(JsonParser jp, DeserializationContext ctxt)
+ throws IOException {
+ JsonNode node = jp.getCodec().readTree(jp);
+ String classTag = node.get("clazz").asText();
+ JsonNode payload = node.get("payload");
+ ObjectMapper mapper = new ObjectMapper();
- try {
- final Class> clazz = Class.forName(classTag);
- return new AtomicAction(clazz, (Oaf) mapper.readValue(payload.toString(), clazz));
- } catch (ClassNotFoundException e) {
- throw new IOException(e);
- }
- }
+ try {
+ final Class> clazz = Class.forName(classTag);
+ return new AtomicAction(clazz, (Oaf) mapper.readValue(payload.toString(), clazz));
+ } catch (ClassNotFoundException e) {
+ throw new IOException(e);
+ }
+ }
}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/EntityType.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/EntityType.java
index 9e4fa7d8ac..54f30cf336 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/EntityType.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/EntityType.java
@@ -1,23 +1,21 @@
+
package eu.dnetlib.dhp.schema.common;
import eu.dnetlib.dhp.schema.oaf.OafEntity;
-/**
- * Actual entity types in the Graph
- */
+/** Actual entity types in the Graph */
public enum EntityType {
+ publication, dataset, otherresearchproduct, software, datasource, organization, project;
- publication, dataset, otherresearchproduct, software, datasource, organization, project;
-
- /**
- * Resolves the EntityType, given the relative class name
- * @param clazz the given class name
- * @param actual OafEntity subclass
- * @return the EntityType associated to the given class
- */
- public static EntityType fromClass(Class clazz) {
-
- return EntityType.valueOf(clazz.getSimpleName().toLowerCase());
- }
+ /**
+ * Resolves the EntityType, given the relative class name
+ *
+ * @param clazz the given class name
+ * @param actual OafEntity subclass
+ * @return the EntityType associated to the given class
+ */
+ public static EntityType fromClass(Class clazz) {
+ return EntityType.valueOf(clazz.getSimpleName().toLowerCase());
+ }
}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/MainEntityType.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/MainEntityType.java
index 7d65e39c09..cda8ba4842 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/MainEntityType.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/MainEntityType.java
@@ -1,9 +1,7 @@
+
package eu.dnetlib.dhp.schema.common;
-/**
- * Main entity types in the Graph
- */
+/** Main entity types in the Graph */
public enum MainEntityType {
-
- result, datasource, organization, project
-}
\ No newline at end of file
+ result, datasource, organization, project
+}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/ModelConstants.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/ModelConstants.java
new file mode 100644
index 0000000000..c6bfff12d4
--- /dev/null
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/ModelConstants.java
@@ -0,0 +1,41 @@
+
+package eu.dnetlib.dhp.schema.common;
+
+import eu.dnetlib.dhp.schema.oaf.Qualifier;
+
+public class ModelConstants {
+
+ public static final String DNET_RESULT_TYPOLOGIES = "dnet:result_typologies";
+
+ public static final String DATASET_RESULTTYPE_CLASSID = "dataset";
+ public static final String PUBLICATION_RESULTTYPE_CLASSID = "publication";
+ public static final String SOFTWARE_RESULTTYPE_CLASSID = "software";
+ public static final String ORP_RESULTTYPE_CLASSID = "other";
+
+ public static Qualifier PUBLICATION_DEFAULT_RESULTTYPE = new Qualifier();
+ public static Qualifier DATASET_DEFAULT_RESULTTYPE = new Qualifier();
+ public static Qualifier SOFTWARE_DEFAULT_RESULTTYPE = new Qualifier();
+ public static Qualifier ORP_DEFAULT_RESULTTYPE = new Qualifier();
+
+ static {
+ PUBLICATION_DEFAULT_RESULTTYPE.setClassid(PUBLICATION_RESULTTYPE_CLASSID);
+ PUBLICATION_DEFAULT_RESULTTYPE.setClassname(PUBLICATION_RESULTTYPE_CLASSID);
+ PUBLICATION_DEFAULT_RESULTTYPE.setSchemeid(DNET_RESULT_TYPOLOGIES);
+ PUBLICATION_DEFAULT_RESULTTYPE.setSchemename(DNET_RESULT_TYPOLOGIES);
+
+ DATASET_DEFAULT_RESULTTYPE.setClassid(DATASET_RESULTTYPE_CLASSID);
+ DATASET_DEFAULT_RESULTTYPE.setClassname(DATASET_RESULTTYPE_CLASSID);
+ DATASET_DEFAULT_RESULTTYPE.setSchemeid(DNET_RESULT_TYPOLOGIES);
+ DATASET_DEFAULT_RESULTTYPE.setSchemename(DNET_RESULT_TYPOLOGIES);
+
+ SOFTWARE_DEFAULT_RESULTTYPE.setClassid(SOFTWARE_RESULTTYPE_CLASSID);
+ SOFTWARE_DEFAULT_RESULTTYPE.setClassname(SOFTWARE_RESULTTYPE_CLASSID);
+ SOFTWARE_DEFAULT_RESULTTYPE.setSchemeid(DNET_RESULT_TYPOLOGIES);
+ SOFTWARE_DEFAULT_RESULTTYPE.setSchemename(DNET_RESULT_TYPOLOGIES);
+
+ ORP_DEFAULT_RESULTTYPE.setClassid(ORP_RESULTTYPE_CLASSID);
+ ORP_DEFAULT_RESULTTYPE.setClassname(ORP_RESULTTYPE_CLASSID);
+ ORP_DEFAULT_RESULTTYPE.setSchemeid(DNET_RESULT_TYPOLOGIES);
+ ORP_DEFAULT_RESULTTYPE.setSchemename(DNET_RESULT_TYPOLOGIES);
+ }
+}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java
index 48f711a030..cdde37fd4a 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java
@@ -1,151 +1,205 @@
+
package eu.dnetlib.dhp.schema.common;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Function;
+
import com.google.common.collect.Maps;
+
import eu.dnetlib.dhp.schema.oaf.*;
-import java.util.Map;
-
-/**
- * Oaf model utility methods.
- */
+/** Oaf model utility methods. */
public class ModelSupport {
- /**
- * Defines the mapping between the actual entity type and the main entity type
- */
- private static Map entityMapping = Maps.newHashMap();
+ /** Defines the mapping between the actual entity type and the main entity type */
+ private static final Map entityMapping = Maps.newHashMap();
- static {
- entityMapping.put(EntityType.publication, MainEntityType.result);
- entityMapping.put(EntityType.dataset, MainEntityType.result);
- entityMapping.put(EntityType.otherresearchproduct, MainEntityType.result);
- entityMapping.put(EntityType.software, MainEntityType.result);
- entityMapping.put(EntityType.datasource, MainEntityType.datasource);
- entityMapping.put(EntityType.organization, MainEntityType.organization);
- entityMapping.put(EntityType.project, MainEntityType.project);
- }
+ static {
+ entityMapping.put(EntityType.publication, MainEntityType.result);
+ entityMapping.put(EntityType.dataset, MainEntityType.result);
+ entityMapping.put(EntityType.otherresearchproduct, MainEntityType.result);
+ entityMapping.put(EntityType.software, MainEntityType.result);
+ entityMapping.put(EntityType.datasource, MainEntityType.datasource);
+ entityMapping.put(EntityType.organization, MainEntityType.organization);
+ entityMapping.put(EntityType.project, MainEntityType.project);
+ }
- /**
- * Defines the mapping between the actual entity types and the relative classes implementing them
- */
- public final static Map entityTypes = Maps.newHashMap();
+ /**
+ * Defines the mapping between the actual entity types and the relative classes implementing them
+ */
+ public static final Map entityTypes = Maps.newHashMap();
- static {
- entityTypes.put(EntityType.datasource, Datasource.class);
- entityTypes.put(EntityType.organization, Organization.class);
- entityTypes.put(EntityType.project, Project.class);
- entityTypes.put(EntityType.dataset, Dataset.class);
- entityTypes.put(EntityType.otherresearchproduct, OtherResearchProduct.class);
- entityTypes.put(EntityType.software, Software.class);
- entityTypes.put(EntityType.publication, Publication.class);
- }
+ static {
+ entityTypes.put(EntityType.datasource, Datasource.class);
+ entityTypes.put(EntityType.organization, Organization.class);
+ entityTypes.put(EntityType.project, Project.class);
+ entityTypes.put(EntityType.dataset, Dataset.class);
+ entityTypes.put(EntityType.otherresearchproduct, OtherResearchProduct.class);
+ entityTypes.put(EntityType.software, Software.class);
+ entityTypes.put(EntityType.publication, Publication.class);
+ }
- public final static Map oafTypes = Maps.newHashMap();
+ public static final Map oafTypes = Maps.newHashMap();
- static {
- oafTypes.put("datasource", Datasource.class);
- oafTypes.put("organization", Organization.class);
- oafTypes.put("project", Project.class);
- oafTypes.put("dataset", Dataset.class);
- oafTypes.put("otherresearchproduct", OtherResearchProduct.class);
- oafTypes.put("software", Software.class);
- oafTypes.put("publication", Publication.class);
- oafTypes.put("relation", Relation.class);
- }
+ static {
+ oafTypes.put("datasource", Datasource.class);
+ oafTypes.put("organization", Organization.class);
+ oafTypes.put("project", Project.class);
+ oafTypes.put("dataset", Dataset.class);
+ oafTypes.put("otherresearchproduct", OtherResearchProduct.class);
+ oafTypes.put("software", Software.class);
+ oafTypes.put("publication", Publication.class);
+ oafTypes.put("relation", Relation.class);
+ }
- private static final String schemeTemplate = "dnet:%s_%s_relations";
+ private static final String schemeTemplate = "dnet:%s_%s_relations";
- private ModelSupport() {
- }
+ private ModelSupport() {
+ }
- /**
- * Checks subclass-superclass relationship.
- *
- * @param subClazzObject Subclass object instance
- * @param superClazzObject Superclass object instance
- * @param Subclass type
- * @param Superclass type
- * @return True if X is a subclass of Y
- */
- public static Boolean isSubClass(X subClazzObject, Y superClazzObject) {
- return isSubClass(subClazzObject.getClass(), superClazzObject.getClass());
- }
+ /**
+ * Checks subclass-superclass relationship.
+ *
+ * @param subClazzObject Subclass object instance
+ * @param superClazzObject Superclass object instance
+ * @param Subclass type
+ * @param Superclass type
+ * @return True if X is a subclass of Y
+ */
+ public static Boolean isSubClass(
+ X subClazzObject, Y superClazzObject) {
+ return isSubClass(subClazzObject.getClass(), superClazzObject.getClass());
+ }
- /**
- * Checks subclass-superclass relationship.
- *
- * @param subClazzObject Subclass object instance
- * @param superClazz Superclass class
- * @param Subclass type
- * @param Superclass type
- * @return True if X is a subclass of Y
- */
- public static Boolean isSubClass(X subClazzObject, Class superClazz) {
- return isSubClass(subClazzObject.getClass(), superClazz);
- }
+ /**
+ * Checks subclass-superclass relationship.
+ *
+ * @param subClazzObject Subclass object instance
+ * @param superClazz Superclass class
+ * @param Subclass type
+ * @param Superclass type
+ * @return True if X is a subclass of Y
+ */
+ public static Boolean isSubClass(
+ X subClazzObject, Class superClazz) {
+ return isSubClass(subClazzObject.getClass(), superClazz);
+ }
- /**
- * Checks subclass-superclass relationship.
- *
- * @param subClazz Subclass class
- * @param superClazz Superclass class
- * @param Subclass type
- * @param Superclass type
- * @return True if X is a subclass of Y
- */
- public static Boolean isSubClass(Class subClazz, Class superClazz) {
- return superClazz.isAssignableFrom(subClazz);
- }
+ /**
+ * Checks subclass-superclass relationship.
+ *
+ * @param subClazz Subclass class
+ * @param superClazz Superclass class
+ * @param Subclass type
+ * @param Superclass type
+ * @return True if X is a subclass of Y
+ */
+ public static Boolean isSubClass(
+ Class subClazz, Class superClazz) {
+ return superClazz.isAssignableFrom(subClazz);
+ }
- /**
- * Lists all the OAF model classes
- *
- * @param
- * @return
- */
- public static Class[] getOafModelClasses() {
- return new Class[]{
- Author.class,
- Context.class,
- Country.class,
- DataInfo.class,
- Dataset.class,
- Datasource.class,
- ExternalReference.class,
- ExtraInfo.class,
- Field.class,
- GeoLocation.class,
- Instance.class,
- Journal.class,
- KeyValue.class,
- Oaf.class,
- OafEntity.class,
- OAIProvenance.class,
- Organization.class,
- OriginDescription.class,
- OtherResearchProduct.class,
- Project.class,
- Publication.class,
- Qualifier.class,
- Relation.class,
- Result.class,
- Software.class,
- StructuredProperty.class
- };
- }
+ /**
+ * Lists all the OAF model classes
+ *
+ * @param
+ * @return
+ */
+ public static Class[] getOafModelClasses() {
+ return new Class[] {
+ Author.class,
+ Context.class,
+ Country.class,
+ DataInfo.class,
+ Dataset.class,
+ Datasource.class,
+ ExternalReference.class,
+ ExtraInfo.class,
+ Field.class,
+ GeoLocation.class,
+ Instance.class,
+ Journal.class,
+ KeyValue.class,
+ Oaf.class,
+ OafEntity.class,
+ OAIProvenance.class,
+ Organization.class,
+ OriginDescription.class,
+ OtherResearchProduct.class,
+ Project.class,
+ Publication.class,
+ Qualifier.class,
+ Relation.class,
+ Result.class,
+ Software.class,
+ StructuredProperty.class
+ };
+ }
- public static String getMainType(final EntityType type) {
- return entityMapping.get(type).name();
- }
+ public static String getMainType(final EntityType type) {
+ return entityMapping.get(type).name();
+ }
- public static boolean isResult(EntityType type) {
- return MainEntityType.result.name().equals(getMainType(type));
- }
+ public static boolean isResult(EntityType type) {
+ return MainEntityType.result.name().equals(getMainType(type));
+ }
- public static String getScheme(final String sourceType, final String targetType) {
- return String.format(schemeTemplate,
- entityMapping.get(EntityType.valueOf(sourceType)).name(),
- entityMapping.get(EntityType.valueOf(targetType)).name());
- }
+ public static String getScheme(final String sourceType, final String targetType) {
+ return String
+ .format(
+ schemeTemplate,
+ entityMapping.get(EntityType.valueOf(sourceType)).name(),
+ entityMapping.get(EntityType.valueOf(targetType)).name());
+ }
-}
\ No newline at end of file
+ public static Function idFn() {
+ return x -> {
+ if (isSubClass(x, Relation.class)) {
+ return idFnForRelation(x);
+ }
+ return idFnForOafEntity(x);
+ };
+ }
+
+ private static String idFnForRelation(T t) {
+ Relation r = (Relation) t;
+ return Optional
+ .ofNullable(r.getSource())
+ .map(
+ source -> Optional
+ .ofNullable(r.getTarget())
+ .map(
+ target -> Optional
+ .ofNullable(r.getRelType())
+ .map(
+ relType -> Optional
+ .ofNullable(r.getSubRelType())
+ .map(
+ subRelType -> Optional
+ .ofNullable(r.getRelClass())
+ .map(
+ relClass -> String
+ .join(
+ source,
+ target,
+ relType,
+ subRelType,
+ relClass))
+ .orElse(
+ String
+ .join(
+ source,
+ target,
+ relType,
+ subRelType)))
+ .orElse(String.join(source, target, relType)))
+ .orElse(String.join(source, target)))
+ .orElse(source))
+ .orElse(null);
+ }
+
+ private static String idFnForOafEntity(T t) {
+ return ((OafEntity) t).getId();
+ }
+}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Author.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Author.java
index 93ab60b05f..b9bd4c5f07 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Author.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Author.java
@@ -1,3 +1,4 @@
+
package eu.dnetlib.dhp.schema.oaf;
import java.io.Serializable;
@@ -6,81 +7,83 @@ import java.util.Objects;
public class Author implements Serializable {
- private String fullname;
+ private String fullname;
- private String name;
+ private String name;
- private String surname;
+ private String surname;
- private Integer rank;
+ private Integer rank;
- private List pid;
+ private List pid;
- private List> affiliation;
+ private List> affiliation;
- public String getFullname() {
- return fullname;
- }
+ public String getFullname() {
+ return fullname;
+ }
- public void setFullname(String fullname) {
- this.fullname = fullname;
- }
+ public void setFullname(String fullname) {
+ this.fullname = fullname;
+ }
- public String getName() {
- return name;
- }
+ public String getName() {
+ return name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public String getSurname() {
- return surname;
- }
+ public String getSurname() {
+ return surname;
+ }
- public void setSurname(String surname) {
- this.surname = surname;
- }
+ public void setSurname(String surname) {
+ this.surname = surname;
+ }
- public Integer getRank() {
- return rank;
- }
+ public Integer getRank() {
+ return rank;
+ }
- public void setRank(Integer rank) {
- this.rank = rank;
- }
+ public void setRank(Integer rank) {
+ this.rank = rank;
+ }
- public List getPid() {
- return pid;
- }
+ public List getPid() {
+ return pid;
+ }
- public void setPid(List pid) {
- this.pid = pid;
- }
+ public void setPid(List pid) {
+ this.pid = pid;
+ }
- public List> getAffiliation() {
- return affiliation;
- }
+ public List> getAffiliation() {
+ return affiliation;
+ }
- public void setAffiliation(List> affiliation) {
- this.affiliation = affiliation;
- }
+ public void setAffiliation(List> affiliation) {
+ this.affiliation = affiliation;
+ }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Author author = (Author) o;
- return Objects.equals(fullname, author.fullname) &&
- Objects.equals(name, author.name) &&
- Objects.equals(surname, author.surname) &&
- Objects.equals(rank, author.rank) &&
- Objects.equals(pid, author.pid) &&
- Objects.equals(affiliation, author.affiliation);
- }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ Author author = (Author) o;
+ return Objects.equals(fullname, author.fullname)
+ && Objects.equals(name, author.name)
+ && Objects.equals(surname, author.surname)
+ && Objects.equals(rank, author.rank)
+ && Objects.equals(pid, author.pid)
+ && Objects.equals(affiliation, author.affiliation);
+ }
- @Override
- public int hashCode() {
- return Objects.hash(fullname, name, surname, rank, pid, affiliation);
- }
+ @Override
+ public int hashCode() {
+ return Objects.hash(fullname, name, surname, rank, pid, affiliation);
+ }
}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Context.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Context.java
index 8092004635..57912c4639 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Context.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Context.java
@@ -1,45 +1,46 @@
+
package eu.dnetlib.dhp.schema.oaf;
import java.io.Serializable;
import java.util.List;
public class Context implements Serializable {
- private String id;
+ private String id;
- private List dataInfo;
+ private List dataInfo;
- public String getId() {
- return id;
- }
+ public String getId() {
+ return id;
+ }
- public void setId(String id) {
- this.id = id;
- }
+ public void setId(String id) {
+ this.id = id;
+ }
- public List getDataInfo() {
- return dataInfo;
- }
+ public List getDataInfo() {
+ return dataInfo;
+ }
- public void setDataInfo(List dataInfo) {
- this.dataInfo = dataInfo;
- }
+ public void setDataInfo(List dataInfo) {
+ this.dataInfo = dataInfo;
+ }
- @Override
- public int hashCode() {
- return id ==null? 0 : id.hashCode();
- }
+ @Override
+ public int hashCode() {
+ return id == null ? 0 : id.hashCode();
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
- Context other = (Context) obj;
+ Context other = (Context) obj;
- return id.equals(other.getId());
- }
+ return id.equals(other.getId());
+ }
}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Country.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Country.java
index b2da92c437..e25fdcade6 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Country.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Country.java
@@ -1,30 +1,34 @@
+
package eu.dnetlib.dhp.schema.oaf;
import java.util.Objects;
public class Country extends Qualifier {
- private DataInfo dataInfo;
+ private DataInfo dataInfo;
- public DataInfo getDataInfo() {
- return dataInfo;
- }
+ public DataInfo getDataInfo() {
+ return dataInfo;
+ }
- public void setDataInfo(DataInfo dataInfo) {
- this.dataInfo = dataInfo;
- }
+ public void setDataInfo(DataInfo dataInfo) {
+ this.dataInfo = dataInfo;
+ }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- if (!super.equals(o)) return false;
- Country country = (Country) o;
- return Objects.equals(dataInfo, country.dataInfo);
- }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ if (!super.equals(o))
+ return false;
+ Country country = (Country) o;
+ return Objects.equals(dataInfo, country.dataInfo);
+ }
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), dataInfo);
- }
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), dataInfo);
+ }
}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/DataInfo.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/DataInfo.java
index 49a1867018..cc77e1ea0c 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/DataInfo.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/DataInfo.java
@@ -1,82 +1,85 @@
+
package eu.dnetlib.dhp.schema.oaf;
import java.io.Serializable;
-import java.util.List;
import java.util.Objects;
public class DataInfo implements Serializable {
- private Boolean invisible = false;
- private Boolean inferred;
- private Boolean deletedbyinference;
- private String trust;
- private String inferenceprovenance;
- private Qualifier provenanceaction;
+ private Boolean invisible = false;
+ private Boolean inferred;
+ private Boolean deletedbyinference;
+ private String trust;
+ private String inferenceprovenance;
+ private Qualifier provenanceaction;
+ public Boolean getInvisible() {
+ return invisible;
+ }
- public Boolean getInvisible() {
- return invisible;
- }
+ public void setInvisible(Boolean invisible) {
+ this.invisible = invisible;
+ }
- public void setInvisible(Boolean invisible) {
- this.invisible = invisible;
- }
+ public Boolean getInferred() {
+ return inferred;
+ }
- public Boolean getInferred() {
- return inferred;
- }
+ public void setInferred(Boolean inferred) {
+ this.inferred = inferred;
+ }
- public void setInferred(Boolean inferred) {
- this.inferred = inferred;
- }
+ public Boolean getDeletedbyinference() {
+ return deletedbyinference;
+ }
- public Boolean getDeletedbyinference() {
- return deletedbyinference;
- }
+ public void setDeletedbyinference(Boolean deletedbyinference) {
+ this.deletedbyinference = deletedbyinference;
+ }
- public void setDeletedbyinference(Boolean deletedbyinference) {
- this.deletedbyinference = deletedbyinference;
- }
+ public String getTrust() {
+ return trust;
+ }
- public String getTrust() {
- return trust;
- }
+ public void setTrust(String trust) {
+ this.trust = trust;
+ }
- public void setTrust(String trust) {
- this.trust = trust;
- }
+ public String getInferenceprovenance() {
+ return inferenceprovenance;
+ }
- public String getInferenceprovenance() {
- return inferenceprovenance;
- }
+ public void setInferenceprovenance(String inferenceprovenance) {
+ this.inferenceprovenance = inferenceprovenance;
+ }
- public void setInferenceprovenance(String inferenceprovenance) {
- this.inferenceprovenance = inferenceprovenance;
- }
+ public Qualifier getProvenanceaction() {
+ return provenanceaction;
+ }
- public Qualifier getProvenanceaction() {
- return provenanceaction;
- }
+ public void setProvenanceaction(Qualifier provenanceaction) {
+ this.provenanceaction = provenanceaction;
+ }
- public void setProvenanceaction(Qualifier provenanceaction) {
- this.provenanceaction = provenanceaction;
- }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ DataInfo dataInfo = (DataInfo) o;
+ return Objects.equals(invisible, dataInfo.invisible)
+ && Objects.equals(inferred, dataInfo.inferred)
+ && Objects.equals(deletedbyinference, dataInfo.deletedbyinference)
+ && Objects.equals(trust, dataInfo.trust)
+ && Objects.equals(inferenceprovenance, dataInfo.inferenceprovenance)
+ && Objects.equals(provenanceaction, dataInfo.provenanceaction);
+ }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- DataInfo dataInfo = (DataInfo) o;
- return Objects.equals(invisible, dataInfo.invisible) &&
- Objects.equals(inferred, dataInfo.inferred) &&
- Objects.equals(deletedbyinference, dataInfo.deletedbyinference) &&
- Objects.equals(trust, dataInfo.trust) &&
- Objects.equals(inferenceprovenance, dataInfo.inferenceprovenance) &&
- Objects.equals(provenanceaction, dataInfo.provenanceaction);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(invisible, inferred, deletedbyinference, trust, inferenceprovenance, provenanceaction);
- }
+ @Override
+ public int hashCode() {
+ return Objects
+ .hash(
+ invisible, inferred, deletedbyinference, trust, inferenceprovenance, provenanceaction);
+ }
}
diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Dataset.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Dataset.java
index 70a6d1f316..07ddbb00e9 100644
--- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Dataset.java
+++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Dataset.java
@@ -1,125 +1,115 @@
+
package eu.dnetlib.dhp.schema.oaf;
import java.io.Serializable;
import java.util.List;
-import java.util.Objects;
+
+import eu.dnetlib.dhp.schema.common.ModelConstants;
public class Dataset extends Result implements Serializable {
- private Field storagedate;
+ private Field storagedate;
- private Field device;
+ private Field device;
- private Field size;
+ private Field size;
- private Field version;
+ private Field