Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #45 from jrmartino/master
Browse files Browse the repository at this point in the history
release for v 1.4.0
  • Loading branch information
jrmartino authored Jun 25, 2020
2 parents ed9f3c9 + 0ffd3c4 commit 5ebdfc5
Show file tree
Hide file tree
Showing 34 changed files with 2,317 additions and 989 deletions.
4 changes: 2 additions & 2 deletions JHU-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ will therefore look like this:

`8675309:policies/e7/3f/26/70/e73f2670-6ef6-4201-bbcd-04631a93d852`

The `policy.proerties` file will have to be kept up to date if additional funders are assigned policies. A different
The `policy.properties` file will have to be kept up to date if additional funders are assigned policies. A different
mechanism will be needed to add additional policies, as we require the policies reference in the properties file to be
already present in the system.

Expand Down Expand Up @@ -165,4 +165,4 @@ must be filled out accordingly. We also have a command line option -m to pass in
The processing of the ResultSet is straightforward - we simply construct a set of hash maps which represent the
column names and the values for each record. We do not assume that the PASS objects in Fedora are updated
only by this application, as there may be some fields on these objects which are not known to COEUS, but
may be populated by other applications eventually (for example ORCID on User, Submissions on Grant, or Policy on Funder).
may be populated by other applications eventually (for example ORCID on User, Submissions on Grant, or Policy on Funder).
2 changes: 1 addition & 1 deletion pass-grant-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>pass-grant-loader</artifactId>
<groupId>org.dataconservancy.pass</groupId>
<version>1.3.0</version>
<version>1.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand All @@ -50,27 +51,28 @@
* use the PassLoader to take {@code List} representing the {@code ResultSet} to push this data into our PASS instance
* via the java pass client.
*
*
* A large percentage of the code here is handling exceptional paths, as this is intended to be run in an automated
* fashion, so care must be taken to log errors, report them to STDOUT, and also send email notifications.
*
* @author [email protected]
*/
abstract class BaseGrantLoaderApp {
private static Logger LOG = LoggerFactory.getLogger(BaseGrantLoaderApp.class);
private static final Logger LOG = LoggerFactory.getLogger(BaseGrantLoaderApp.class);
private EmailService emailService;

private File appHome;
private final File appHome;
private String startDate;
private String awardEndDate;
private final String awardEndDate;
private File updateTimestampsFile;
private boolean email;
private String mode;
private String action;
private String dataFileName;
private final boolean email;
private final String mode;
private final String action;
private final String dataFileName;
private boolean local = false;
private boolean timestamp = true;
private boolean timestamp = false;

private String updateTimestampsFileName;
private final String updateTimestampsFileName;

/**
* Constructor for this class
Expand Down Expand Up @@ -247,7 +249,7 @@ void run() throws PassCliException {
try (FileInputStream fis = new FileInputStream(dataFile);
ObjectInputStream in = new ObjectInputStream(fis)
) {
resultSet = (List<Map<String, String>>)in.readObject();
resultSet = Collections.unmodifiableList((List<Map<String, String>>) in.readObject());
} catch (IOException | ClassNotFoundException ex) {
ex.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.dataconservancy.pass.grant.cli;

/**
* A class containing all error strings for errors caught by the Loader Apps
*/
class DataLoaderErrors {
static String ERR_HOME_DIRECTORY_NOT_FOUND = "No home directory found for the application. Please specify a valid absolute path.";
static String ERR_HOME_DIRECTORY_NOT_READABLE_AND_WRITABLE = "Supplied home directory must be readable" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import org.slf4j.LoggerFactory;

/**
* An email service for reporting errors or results of running the {@code CoeusGrantLoaderApp}
* An email service for reporting errors or results of running a GrantLoaderApp
* @author [email protected]
*/
class EmailService {
private static Logger LOG = LoggerFactory.getLogger(EmailService.class);
private Properties mailProperties;
private static final Logger LOG = LoggerFactory.getLogger(EmailService.class);
private final Properties mailProperties;

/**
* The constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
*/

package org.dataconservancy.pass.grant.cli;

import org.dataconservancy.pass.grant.data.CoeusConnector;
import org.dataconservancy.pass.grant.data.DateTimeUtil;
import org.dataconservancy.pass.grant.data.GrantConnector;
import org.dataconservancy.pass.grant.data.JhuPassUpdater;
import org.dataconservancy.pass.grant.data.PassUpdater;
import org.dataconservancy.pass.grant.data.*;

import java.util.Properties;

class JhuGrantLoaderApp extends BaseGrantLoaderApp {

JhuGrantLoaderApp(String startDate, String awardEndDate, boolean email, String mode, String action, String dataFileName) {
boolean init;

JhuGrantLoaderApp(String startDate, String awardEndDate, boolean email, String mode, String action, String dataFileName, boolean init) {
super(startDate, awardEndDate, email, mode, action, dataFileName);
super.setTimestamp(true);
this.init = init;
}

@Override
Expand All @@ -43,6 +41,9 @@ GrantConnector configureConnector(Properties connectionProperties, Properties po

@Override
PassUpdater configureUpdater() {
if ( init ) {
return new JhuPassInitUpdater();
}
return new JhuPassUpdater();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public class JhuGrantLoaderCLI {
"01/01/2011")
private static String awardEndDate = "01/01/2011";

/** Specifies whether this run is an "initializing run" which is allowed to overwrite normally non-writable fields on grants */
@Option(name = "-i", aliases = {"-init", "--init", "-initialize", "--initialize" }, usage = "When set to true, changes the behavior of the loader to allow it" +
"to update all fields stored on grants with info coming in from the pull. This is useful when updating existing grant records due to a change in policy" +
"about what the semantics of the stored records are.")
private static boolean init = false;

/** Specifies an optional action - either "pull" or "load" - to restrict the operation of the application to only pull data
* from COEUS to store in a file, or to only load into PASS data taken from a stored file, respectively. In either case, the path to
Expand Down Expand Up @@ -113,7 +118,7 @@ public static void main(String[] args) {
}

/* Run the package generation application proper */
JhuGrantLoaderApp app = new JhuGrantLoaderApp(startDate, awardEndDate, email, mode, action, dataFileName);
JhuGrantLoaderApp app = new JhuGrantLoaderApp(startDate, awardEndDate, email, mode, action, dataFileName, init);
app.run();
System.exit((0));
} catch (CmdLineException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetupTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -28,13 +27,16 @@
import java.io.IOException;
import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Test classs for email service
* @author [email protected]
*/
public class EmailServiceTest {

private Properties mailProperties = System.getProperties();
private final Properties mailProperties = System.getProperties();
private EmailService underTest;
private GreenMail testServer;

Expand Down Expand Up @@ -63,7 +65,7 @@ public void setup() throws InterruptedException {

if (!started) {
// try one more time
Thread.sleep(5000l);
Thread.sleep(5000L);
testServer.start();
}

Expand All @@ -80,14 +82,14 @@ public void testSendMessage() throws MessagingException, IOException {
String messageSubject = "TEST";
underTest.sendEmailMessage(messageSubject, messageBody);
// Check that only one message was sent
Integer numMessages = testServer.getReceivedMessages().length;
Assert.assertTrue("Expected only one message, got " + numMessages, numMessages == 1);
int numMessages = testServer.getReceivedMessages().length;
assertEquals("Expected only one message, got " + numMessages, 1, numMessages);

// Check that the message is just a plaintext message
MimeMessage message = testServer.getReceivedMessages()[0];
Assert.assertTrue("Subject of message was not correct", message.getSubject().equals(messageSubject));
Assert.assertTrue("Content of message was not a string as expected", message.getContent() instanceof String);
Assert.assertTrue(message.getContent().toString().contains(messageBody));
assertEquals("Subject of message was not correct", message.getSubject(), messageSubject);
assertTrue("Content of message was not a string as expected", message.getContent() instanceof String);
assertTrue(message.getContent().toString().contains(messageBody));
}

@After
Expand Down
2 changes: 1 addition & 1 deletion pass-grant-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>pass-grant-loader</artifactId>
<groupId>org.dataconservancy.pass</groupId>
<version>1.3.0</version>
<version>1.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Loading

0 comments on commit 5ebdfc5

Please sign in to comment.