Skip to content
Permalink
Browse files

move English to bundle, add tests for no contacts IQSS#1916

  • Loading branch information...
pdurbin committed Apr 13, 2018
1 parent 28bedb8 commit 34df960bcf2b38b1812029841ddabb7d0a61eac1
@@ -129,8 +129,12 @@ contact.contact=Contact
# Bundle file editors, please note that these "contact.context" messages are used in tests.
contact.context.dataverse.intro=The message below was sent from the Contact button at {0}/dataverse/{1}\n\n
contact.context.dataverse.ending=
contact.context.dataverse.noContact=There is no contact address on file for this dataverse so this message is being sent to the system address.\n\n
contact.context.dataset.greeting.helloFirstLast=Hello {0} {1},
contact.context.dataset.greeting.organization=Attention Dataset Contact
contact.context.dataset.intro={0}\n\nYou have just been sent the following message from {1} via the {2} hosted dataset titled "{3}" ({4}):\n\n---\n\n
contact.context.dataset.ending=\n\n---\n\n{0}\n{1}\n\nGo to dataset {2}/dataset.xhtml?persistentId={3}\n\nYou received this email because you have been listed as a contact for the dataset. If you believe this was an error, please contact {4} at {5}. To respond directly to the individual who sent the message, simply reply to this email.
contact.context.dataset.noContact=There is no contact address on file for this dataset so this message is being sent to the system address.\n\n---\n\n
contact.context.file.intro=The message below was sent from the Contact button at {0}/file.xhtml?fileId={1}\n\n
contact.context.file.ending=

@@ -21,6 +21,8 @@

private static final Logger logger = Logger.getLogger(FeedbackUtil.class.getCanonicalName());

private static final String NO_DATASET_CONTACT_INTRO = BundleUtil.getStringFromBundle("contact.context.dataset.noContact");

// TODO: consider changing "recipient" into an object called something like FeedbackTarget
public static List<Feedback> gatherFeedback(DvObject recipient, DataverseSession dataverseSession, String messageSubject, String userMessage, InternetAddress systemAddress, String userEmail, String dataverseSiteUrl, String installationBrandName, String supportTeamName) {
List<Feedback> feedbacks = new ArrayList<>();
@@ -40,8 +42,7 @@
if (!feedbacks.isEmpty()) {
return feedbacks;
} else {
// FIXME: Put this English in the bundle.
String dataverseContextIntroError = "There is no contact address on file for this dataverse so this message is being sent to the system address.\n\n" + dataverseContextIntro;
String dataverseContextIntroError = BundleUtil.getStringFromBundle("contact.context.dataverse.noContact") + dataverseContextIntro;
Feedback feedback = new Feedback(userEmail, systemAddress.getAddress(), messageSubject, dataverseContextIntroError + userMessage + dataverseContextEnding);
feedbacks.add(feedback);
return feedbacks;
@@ -61,13 +62,11 @@
if (!feedbacks.isEmpty()) {
return feedbacks;
} else {
// FIXME: Put this English in the bundle.
String datasetContextIntroError = "There is no contact address on file for this dataset so this message is being sent to the system address.\n\n";
Feedback feedback = new Feedback(userEmail, systemAddress.getAddress(), messageSubject, datasetContextIntroError + userMessage + datasetContextEnding);
Feedback feedback = new Feedback(userEmail, systemAddress.getAddress(), messageSubject, NO_DATASET_CONTACT_INTRO + userMessage + datasetContextEnding);
feedbacks.add(feedback);
return feedbacks;
}
} else if (recipient.isInstanceofDataFile()) {
} else {
DataFile datafile = (DataFile) recipient;
List<DvObjectContact> datasetContacts = getDatasetContacts(datafile.getOwner());
String fileContextIntro = BundleUtil.getStringFromBundle("contact.context.file.intro", Arrays.asList(dataverseSiteUrl, datafile.getId().toString()));
@@ -76,11 +75,14 @@
Feedback feedback = new Feedback(userEmail, datasetContact.getEmail(), messageSubject, fileContextIntro + userMessage + fileContextEnding);
feedbacks.add(feedback);
}
// TODO: what if feedbacks is empty?
return feedbacks;
} else {
logger.warning("The only DvObjects supported are Dataverse, Dataset, and DataFile. No feedback sent.");
return Collections.EMPTY_LIST;
if (!feedbacks.isEmpty()) {
return feedbacks;
} else {
String datasetContextEnding = "";
Feedback feedback = new Feedback(userEmail, systemAddress.getAddress(), messageSubject, NO_DATASET_CONTACT_INTRO + userMessage + datasetContextEnding);
feedbacks.add(feedback);
return feedbacks;
}
}
} else {
if (systemAddress != null) {
@@ -119,9 +121,7 @@ private static String loggedInUserEmail(DataverseSession dataverseSession) {
List<DvObjectContact> retList = new ArrayList<>();
for (DatasetField dsf : dataset.getLatestVersion().getDatasetFields()) {
if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.datasetContact)) {
// FIXME: Put English in bundle
String saneDefaultForName = "dataset contact";
String contactName = saneDefaultForName;
String contactName = null;
String contactEmail = null;
for (DatasetFieldCompoundValue authorValue : dsf.getDatasetFieldCompoundValues()) {
for (DatasetField subField : authorValue.getChildDatasetFields()) {
@@ -162,12 +162,10 @@ private static String getGreeting(DvObjectContact firstDatasetContact) {
String[] lastFirstParts = lastFirstString.split(",");
String last = lastFirstParts[0];
String first = lastFirstParts[1];
// TODO: Move this English to the bundle.
return "Hello " + first.trim() + " " + last.trim() + ",";
return BundleUtil.getStringFromBundle("contact.context.dataset.greeting.helloFirstLast", Arrays.asList(first.trim(), last.trim()));
} catch (Exception ex) {
logger.warning("problem in getGreeting: " + ex);
// TODO: Move this English to the bundle.
return "Attention Dataset Contact";
return BundleUtil.getStringFromBundle("contact.context.dataset.greeting.organization");
}
}

@@ -35,8 +35,11 @@
import javax.json.JsonReader;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.validation.constraints.AssertTrue;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;

public class FeedbackUtilTest {
@@ -49,6 +52,7 @@
private static DataverseSession dataverseSessionAuthenticated;
private static DatasetVersion dsVersion;
private static DatasetVersion dsVersion2;
private static DatasetVersion dsVersionNoContacts;
private static MockDatasetFieldSvc datasetFieldTypeSvc;
private static InternetAddress systemAddress;
private static final String systemEmail = "support@librascholar.edu";
@@ -151,6 +155,13 @@ public static void setUpClass() throws IOException, JsonParseException, AddressE
JsonParser jsonParser2 = new JsonParser(datasetFieldTypeSvc, null, null);
dsVersion2 = jsonParser2.parseDatasetVersion(json12.getJsonObject("datasetVersion"));

File datasetVersionJsonNoContacts = new File("tests/data/datasetNoContacts.json");
String datasetVersionAsJsonNoContacts = new String(Files.readAllBytes(Paths.get(datasetVersionJsonNoContacts.getAbsolutePath())));
JsonReader jsonReaderNoContacts = Json.createReader(new StringReader(datasetVersionAsJsonNoContacts));
JsonObject jsonNoContacts = jsonReaderNoContacts.readObject();
JsonParser jsonParserNoContacts = new JsonParser(datasetFieldTypeSvc, null, null);
dsVersionNoContacts = jsonParserNoContacts.parseDatasetVersion(jsonNoContacts.getJsonObject("datasetVersion"));

FeedbackUtil justForCodeCoverage = new FeedbackUtil();
}

@@ -238,6 +249,55 @@ public void testGatherFeedbackOnDataset() {
assertEquals(expected, feedback.getBody());
}

@Test
public void testGatherFeedbackOnDatasetNoContacts() {
Dataset dataset = new Dataset();

List<DatasetVersion> versions = new ArrayList<>();
DatasetVersion datasetVersionIn = dsVersionNoContacts;
datasetVersionIn.setVersionState(DatasetVersion.VersionState.RELEASED);
versions.add(datasetVersionIn);
dataset.setVersions(versions);

dataset.setProtocol("doi");
dataset.setAuthority("10.7910/DVN");
dataset.setIdentifier("TJCLKP");
Dataverse dataverse = new Dataverse();
dataset.setOwner(dataverse);

DataverseSession dataverseSession = null;
String messageSubject = "nice file";
String userMessage = "Let's talk!";
List<Feedback> feedbacks = FeedbackUtil.gatherFeedback(dataset, dataverseSession, messageSubject, userMessage, systemAddress, userEmail, baseUrl, installationBrandName, supportTeamName);
System.out.println("feedbacks: " + feedbacks);
assertEquals(1, feedbacks.size());
Feedback feedback = feedbacks.get(0);
System.out.println("Subject: " + feedback.getSubject());
System.out.println("Body: " + feedback.getBody());
System.out.println("From: " + feedback.getFromEmail());
System.out.println("To: " + feedback.getToEmail());
assertEquals(systemEmail, feedback.getToEmail());
assertEquals(messageSubject, feedback.getSubject());
String expected = "There is no contact address on file for this dataset so this message is being sent to the system address.\n\n"
// FIXME: Add more context for person who receives systemEmail messages.
// FIXME: change from "personClickingContactOrSupportButton@example.com" to "Homer Simpson" or whatever (add to contact form).
// + "You have just been sent the following message from " + feedback.getFromEmail() + " "
// + "via the " + installationBrandName + " hosted dataset "
// + "titled \"Darwin's Finches\" (doi:10.7910/DVN/TJCLKP):\n\n"
+ "---\n\n"
+ userMessage + "\n\n"
+ "---\n\n"
+ supportTeamName + "\n"
+ systemEmail + "\n\n"
+ "Go to dataset https://dataverse.librascholar.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/TJCLKP\n\n"
+ "You received this email because you have been listed as a contact for the dataset. If you believe this was an error, please contact " + supportTeamName + " at " + systemEmail + ". To respond directly to the individual who sent the message, simply reply to this email.";
System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
System.out.println("EXPECTED:\n\n" + expected);
System.out.println("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
System.out.println("ACTUAL:\n\n" + feedback.getBody());
assertEquals(expected, feedback.getBody());
}

@Test
public void testGatherFeedbackOnFile() {

@@ -286,6 +346,56 @@ public void testGatherFeedbackOnFile() {
assertEquals(messageSubject, feedback.getSubject());
assertEquals("finch@mailinator.com", feedback.getToEmail());
assertEquals("The message below was sent from the Contact button at https://dataverse.librascholar.edu/file.xhtml?fileId=42\n\n" + userMessage, feedback.getBody());

}

@Test
public void testGatherFeedbackOnFileNoContacts() {

FileMetadata fmd = new FileMetadata();
// DatasetVersion dsVersion = new DatasetVersion();
DataFile dataFile = new DataFile();

dataFile.setId(42l);
List<DataFileTag> dataFileTags = new ArrayList<>();
DataFileTag tag = new DataFileTag();
tag.setTypeByLabel("Survey");
dataFileTags.add(tag);
dataFile.setTags(dataFileTags);
fmd.setDatasetVersion(dsVersionNoContacts);
fmd.setDataFile(dataFile);
List<DataFileCategory> fileCategories = new ArrayList<>();
DataFileCategory dataFileCategory = new DataFileCategory();
dataFileCategory.setName("Data");
fileCategories.add(dataFileCategory);
fmd.setCategories(fileCategories);
Dataset dataset = new Dataset();
dataFile.setOwner(dataset);

List<DatasetVersion> versions = new ArrayList<>();
DatasetVersion datasetVersionIn = dsVersionNoContacts;
datasetVersionIn.setVersionState(DatasetVersion.VersionState.RELEASED);
versions.add(datasetVersionIn);
dataset.setVersions(versions);

dataset.setProtocol("doi");
dataset.setAuthority("10.7910/DVN");
dataset.setIdentifier("TJCLKP");
Dataverse dataverse = new Dataverse();
dataset.setOwner(dataverse);

String messageSubject = "nice file";
String userMessage = "Let's talk!";
List<Feedback> feedbacks = FeedbackUtil.gatherFeedback(dataFile, dataverseSessionNull, messageSubject, userMessage, systemAddress, userEmail, baseUrl, installationBrandName, supportTeamName);
Feedback feedback = feedbacks.get(0);
System.out.println("feedback: " + feedback);
System.out.println("Subject: " + feedback.getSubject());
System.out.println("Body: " + feedback.getBody());
System.out.println("From: " + feedback.getFromEmail());
System.out.println("To: " + feedback.getToEmail());
assertEquals(messageSubject, feedback.getSubject());
assertEquals("support@librascholar.edu", feedback.getToEmail());
assertTrue(feedback.getBody().startsWith("There is no contact address on file for this dataset so this message is being sent to the system address."));
}

@Test
@@ -0,0 +1,61 @@
{
"datasetVersion": {
"metadataBlocks": {
"citation": {
"fields": [
{
"value": "Darwin's Finches",
"typeClass": "primitive",
"multiple": false,
"typeName": "title"
},
{
"value": [
{
"authorName": {
"value": "Finch, Fiona",
"typeClass": "primitive",
"multiple": false,
"typeName": "authorName"
},
"authorAffiliation": {
"value": "Birds Inc.",
"typeClass": "primitive",
"multiple": false,
"typeName": "authorAffiliation"
}
}
],
"typeClass": "compound",
"multiple": true,
"typeName": "author"
},
{
"value": [
{
"dsDescriptionValue": {
"value": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.",
"multiple": false,
"typeClass": "primitive",
"typeName": "dsDescriptionValue"
}
}
],
"typeClass": "compound",
"multiple": true,
"typeName": "dsDescription"
},
{
"value": [
"Medicine, Health and Life Sciences"
],
"typeClass": "controlledVocabulary",
"multiple": true,
"typeName": "subject"
}
],
"displayName": "Citation Metadata"
}
}
}
}

0 comments on commit 34df960

Please sign in to comment.
You can’t perform that action at this time.