Skip to content

Commit 0b69ecf

Browse files
authored
Added options to set metadataLanguages and different PID protocols (#30)
* Add metadatalanguage to Dataset and DatasetFacade, and test it * Upload files with protocols other than DOI
1 parent 22da346 commit 0b69ecf

8 files changed

Lines changed: 97 additions & 60 deletions

File tree

src/integration-test/java/com/researchspace/dataverse/http/DatasetOperationsTest.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121

2222
import static com.researchspace.dataverse.entities.facade.DatasetTestFactory.createFacade;
23+
import static com.researchspace.dataverse.entities.facade.DatasetTestFactory.createFacadeWithMetadataLanguage;
2324
import static org.junit.Assert.*;
2425

2526

@@ -38,14 +39,14 @@
3839
See the License for the specific language governing permissions and
3940
limitations under the License.
4041
</pre>
41-
*/
42+
*/
4243

4344
public class DatasetOperationsTest extends AbstractIntegrationTest {
44-
45+
4546
@Before
4647
public void setup() throws Exception {
4748
super.setUp();
48-
}
49+
}
4950

5051
File exampleDatasetJson = new File("src/integration-test/resources/dataset-create-new-all-default-fields.json");
5152
@Test
@@ -117,22 +118,22 @@ public void testPostGetDeleteDataset() throws IOException, InterruptedException,
117118
DatasetFacade facade = createFacade();
118119
//create a new, unpublished Dataverse
119120
String newAlias = RandomStringUtils.randomAlphabetic(10);
120-
DataversePost toCreate = DataverseOperationsTest.createADataverse(newAlias);
121-
DataversePost newDV = dataverseOps.createNewDataverse(dataverseAlias, toCreate).getData();
122-
121+
DataversePost toCreate = DataverseOperationsTest.createADataverse(newAlias);
122+
DataversePost newDV = dataverseOps.createNewDataverse(dataverseAlias, toCreate).getData();
123+
123124
// create Dataset in child dataverse
124125
Identifier datasetId = dataverseOps.createDataset(facade, newDV.getAlias());
125126
assertNotNull(datasetId.getId());
126127
assertNotNull(datasetId.getPersistentId());
127128
Dataset ds = datasetOps.getDataset(datasetId);
128129
String doiId = ds.getDoiId().get();
129-
datasetOps.uploadFile(doiId, getTestFile());
130-
130+
datasetOps.uploadFile(doiId, getTestFile(), ds.getProtocol());
131+
131132
//publishing will fail, as parent DV is not published
132133
DataverseResponse<PublishedDataset> response = datasetOps.publishDataset (datasetId, Version.MAJOR);
133134
assertNull(response.getData());
134135
assertNotNull(response.getMessage());
135-
136+
136137
facade.setTitle("Updated title2");
137138
datasetOps.updateDataset(facade, datasetId);
138139
List<DatasetVersion> versions = datasetOps.getDatasetVersions(datasetId);
@@ -141,7 +142,23 @@ public void testPostGetDeleteDataset() throws IOException, InterruptedException,
141142
String msg = datasetOps.deleteDataset(datasetId).getMessage();
142143
dataverseOps.deleteDataverse(newAlias);
143144
assertNotNull(msg);
144-
145+
146+
}
147+
148+
@Test
149+
public void testCreateDatasetWithMetadataLanguage() {
150+
DatasetFacade facade = createFacadeWithMetadataLanguage();
151+
Identifier datasetId = dataverseOps.createDataset(facade, dataverseAlias);
152+
assertNotNull(datasetId.getId());
153+
assertNotNull(datasetId.getPersistentId());
154+
}
155+
156+
@Test
157+
public void testUploadFile() {
158+
DatasetFacade facade = createFacadeWithMetadataLanguage();
159+
Identifier datasetId = dataverseOps.createDataset(facade, dataverseAlias);
160+
Dataset ds = datasetOps.getDataset(datasetId);
161+
datasetOps.uploadFile(ds.getDoiId().get(), getTestFile(), ds.getProtocol());
145162
}
146163

147164
private File getTestFile() {

src/main/java/com/researchspace/dataverse/api/v1/DatasetOperations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ DatasetFileList uploadNativeFile(InputStream data, long contentLength, FileUploa
8383
* @param doi The DOI of the Dataset
8484
* @param file The file to add to the DataSet
8585
*/
86-
void uploadFile(String doi, File file);
86+
void uploadFile(String doi, File file, String protocol);
8787

8888
/**
8989
* Uploads a file using a data stream.
@@ -92,7 +92,7 @@ DatasetFileList uploadNativeFile(InputStream data, long contentLength, FileUploa
9292
* @param inputStream Stream of data to upload as a file in Dataverse.
9393
* @param filename Contents of the field "name" that will appear as in Dataverse.
9494
*/
95-
void uploadFile(String doi, InputStream inputStream, String filename);
95+
void uploadFile(String doi, InputStream inputStream, String filename, String protocol);
9696

9797
/**
9898
* Deletes a {@link Dataset}

src/main/java/com/researchspace/dataverse/entities/Dataset.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ public class Dataset {
3333
private Long id;
3434
private String identifier, protocol, authority;
3535
private URL persistentUrl;
36+
private String metadataLanguage;
3637

3738
/**
38-
* Getter for the DOI String used to identify a dataset for SWORD upload
39+
* Getter for the DOI String or other persistent identifier used to identify a dataset for SWORD upload
3940
* @return an {@link Optional}. Will be <code>null</code> if <code>persistentURL</code> is not set.
4041
*/
4142
public Optional<String> getDoiId (){

src/main/java/com/researchspace/dataverse/entities/facade/DatasetBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ public Dataset build(DatasetFacade facade) {
8484
citation.setFields(fields);
8585
Dataset toSubmit = new Dataset();
8686
toSubmit.setDatasetVersion(dv);
87+
String metadataLanguage = facade.getMetadataLanguage();
88+
if (metadataLanguage != null) {
89+
toSubmit.setMetadataLanguage(facade.getMetadataLanguage());
90+
}
8791
return toSubmit;
8892
}
8993

src/main/java/com/researchspace/dataverse/entities/facade/DatasetFacade.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class DatasetFacade {
5050
private Date productionDate;
5151
private String productionPlace;
5252
private @Singular List<DatasetContributor> contributors;
53+
private String metadataLanguage;
5354

5455
/**
5556
* Returns a copy if the internally stored Date

src/main/java/com/researchspace/dataverse/http/DataverseOperationsImplV1.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,21 @@ private DatasetFileList getDatasetFileList(FileUploadMetadata metadata, Identifi
236236
* @see com.researchspace.dataverse.http.DataverseAPI#uploadFile(java.lang.String, java.io.File)
237237
*/
238238
@Override
239-
public void uploadFile (String doi, File file) {
239+
public void uploadFile (String doi, File file, String protocol) {
240240
try {
241-
this.uploadFile(doi, new FileInputStream(file), file.getName());
241+
this.uploadFile(doi, new FileInputStream(file), file.getName(), protocol);
242242
} catch (FileNotFoundException e) {
243243
e.printStackTrace();
244244
}
245245
}
246246

247247
@Override
248-
public void uploadFile(String doi, InputStream file, String filename) {
248+
public void uploadFile(String doi, InputStream file, String filename, String protocol) {
249249
FileUploader uploader = new FileUploader();
250250
try {
251-
uploader.deposit(file, filename, apiKey, new URI(serverURL), doi);
251+
uploader.deposit(file, filename, apiKey, new URI(serverURL), doi, protocol);
252252
} catch (IOException | SWORDClientException | ProtocolViolationException | URISyntaxException e) {
253-
log.error("Couldn't upload file {} with doi {} : {}", filename, doi.toString(), e.getMessage());
253+
log.error("Couldn't upload file {} with {} {} : {}", filename, protocol, doi.toString(), e.getMessage());
254254
throw new RestClientException(e.getMessage());
255255
} catch (SWORDError error) {
256256
if (!StringUtils.isEmpty(error.getErrorBody())) {

src/main/java/com/researchspace/dataverse/sword/FileUploader.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public class FileUploader {
5656
* @throws SWORDError
5757
* @throws ProtocolViolationException
5858
*/
59-
public DepositReceipt deposit(File file, String apiKey, URI dataverseServer, String doi)
59+
public DepositReceipt deposit(File file, String apiKey, URI dataverseServer, String doi, String protocol)
6060
throws IOException, SWORDClientException, SWORDError, ProtocolViolationException {
61-
return this.deposit(new FileInputStream(file), file.getName(), apiKey, dataverseServer, doi);
61+
return this.deposit(new FileInputStream(file), file.getName(), apiKey, dataverseServer, doi, protocol);
6262
}
6363

6464

@@ -70,13 +70,14 @@ public DepositReceipt deposit(File file, String apiKey, URI dataverseServer, Str
7070
* @param apiKey Key used to authenticate actions into the goal dataverse instance.
7171
* @param dataverseServer URL of the dataverse instance to attack.
7272
* @param doi To identify the dataset that is the goal of the file upload.
73+
* @param protocol The protocol used for persistent identification
7374
* @return Information of the result of the upload via a {@code DepositReceipt} instance.
7475
* @throws IOException Thrown when a IO error occurs, which is a general error.
7576
* @throws SWORDClientException Thrown when an exception happens inside the SWORD client.
7677
* @throws SWORDError Thrown when an exception happens inside the SWORD client.
7778
* @throws ProtocolViolationException Thrown for unknown reasons.
7879
*/
79-
public DepositReceipt deposit(InputStream is, String filename, String apiKey, URI dataverseServer, String doi)
80+
public DepositReceipt deposit(InputStream is, String filename, String apiKey, URI dataverseServer, String doi, String protocol)
8081
throws IOException, SWORDClientException, SWORDError, ProtocolViolationException {
8182
SWORDClient cli = new SWORDClient();
8283
Deposit dep = new Deposit();
@@ -87,8 +88,8 @@ public DepositReceipt deposit(InputStream is, String filename, String apiKey, UR
8788

8889
AuthCredentials cred = new AuthCredentials(apiKey, "");
8990

90-
String depositURI = dataverseServer.toString() + "/dvn/api/data-deposit/v1.1/swordv2/edit-media/study/doi:"
91-
+ doi;
91+
String depositURI = dataverseServer.toString() + "/dvn/api/data-deposit/v1.1/swordv2/edit-media/study/"
92+
+ protocol + ":" + doi;
9293
DepositReceipt rct = cli.deposit(depositURI, dep, cred);
9394
log.info("Deposit received with status {}" ,rct.getStatusCode());
9495
return rct;

src/test/java/com/researchspace/dataverse/entities/facade/DatasetTestFactory.java

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,45 @@ public class DatasetTestFactory {
3434
* Creates a complex DataSet object
3535
* @return
3636
* @throws MalformedURLException
37-
* @throws URISyntaxException
37+
* @throws URISyntaxException
3838
*/
39-
public static DatasetFacade createFacade() throws MalformedURLException, URISyntaxException {
39+
public static DatasetFacade createFacade() throws MalformedURLException, URISyntaxException {
4040
return DatasetFacade.builder()
41-
.author(buildAnAuthor()).author(buildAnotherAuthor())
42-
.title("title1")
43-
.contact(buildAContact()).contact(buildAnotherContact())
44-
.description(buildADesc())
45-
.keyword(buildAKeyword("key1")).keyword(buildAKeyword("key2"))
46-
.topicClassification(buildATopicClassification("topic1"))
47-
.publication(buildAPublication())
48-
.producer(buildAProducer())
49-
.productionDate(new Date())
50-
.productionPlace("Edinburgh, UK")
51-
.contributor(buildAContributor("Fred")).contributor(buildAContributor("Tim"))
52-
.subject("Chemistry")
53-
.depositor("A depositor")
54-
.subtitle(" A subtitle")
55-
.alternativeTitle("altTitle")
56-
.alternativeURL(new URL("https://www.myrepo.com"))
57-
.note("Some note")
58-
.languages(Arrays.asList(new String []{"English", "French"}))
59-
.build();
41+
.author(buildAnAuthor()).author(buildAnotherAuthor())
42+
.title("title1")
43+
.contact(buildAContact()).contact(buildAnotherContact())
44+
.description(buildADesc())
45+
.keyword(buildAKeyword("key1")).keyword(buildAKeyword("key2"))
46+
.topicClassification(buildATopicClassification("topic1"))
47+
.publication(buildAPublication())
48+
.producer(buildAProducer())
49+
.productionDate(new Date())
50+
.productionPlace("Edinburgh, UK")
51+
.contributor(buildAContributor("Fred")).contributor(buildAContributor("Tim"))
52+
.subject("Chemistry")
53+
.depositor("A depositor")
54+
.subtitle(" A subtitle")
55+
.alternativeTitle("altTitle")
56+
.alternativeURL(new URL("https://www.myrepo.com"))
57+
.note("Some note")
58+
.languages(Arrays.asList(new String[] { "English", "French" }))
59+
.build();
6060
}
6161

62-
private static DatasetContributor buildAContributor(String name) {
62+
public static DatasetFacade createFacadeWithMetadataLanguage() {
63+
return DatasetFacade.builder()
64+
.author(buildAnAuthor())
65+
.title("test")
66+
.metadataLanguage("hu")
67+
.description(buildADesc())
68+
.subject("Chemistry")
69+
.languages(Arrays.asList(new String[] { "English", "French" }))
70+
.depositor("A depositor")
71+
.contact(buildAContact())
72+
.build();
73+
}
74+
75+
private static DatasetContributor buildAContributor(String name) {
6376
return DatasetContributor.builder()
6477
.name(name)
6578
.type(ContributorType.ProjectLeader)
@@ -92,42 +105,42 @@ private static DatasetTopicClassification buildATopicClassification(String value
92105
}
93106

94107
private static DatasetKeyword buildAKeyword(String key) throws URISyntaxException {
95-
return DatasetKeyword.builder().value(key).vocabulary("keywordVocab")
96-
.vocabularyURI(new URI("https://vocab.com")).build();
108+
return DatasetKeyword.builder().value(key).vocabulary("keywordVocab")
109+
.vocabularyURI(new URI("https://vocab.com")).build();
97110
}
98111

99112
private static DatasetDescription buildADesc() {
100-
return DatasetDescription.builder()
101-
.date(new Date()).description("some desc")
102-
.build();
113+
return DatasetDescription.builder()
114+
.date(new Date()).description("some desc")
115+
.build();
103116
}
104117

105118
static DatasetContact buildAContact() {
106119
return DatasetContact.builder()
107120
.datasetContactAffiliation("Some place").datasetContactEmail("contact@email.com").datasetContactName("Sarah Contact")
108121
.build();
109122
}
110-
111-
static DatasetContact buildAnotherContact() {
123+
124+
static DatasetContact buildAnotherContact() {
112125
return DatasetContact.builder()
113126
.datasetContactAffiliation("Another place")
114127
.datasetContactEmail("contact2@email.com")
115128
.datasetContactName("Brian Contact2")
116129
.build();
117130
}
118131

119-
static DatasetAuthor buildAnotherAuthor() {
132+
static DatasetAuthor buildAnotherAuthor() {
120133
return DatasetAuthor.builder().authorName("John Smith")
121-
.authorAffiliation("Dataverse")
122-
.authorIdentifierScheme("ISNI")
123-
.authorIdentifier("1234-5678").build();
134+
.authorAffiliation("Dataverse")
135+
.authorIdentifierScheme("ISNI")
136+
.authorIdentifier("1234-5678").build();
124137
}
125138

126-
static DatasetAuthor buildAnAuthor() {
139+
static DatasetAuthor buildAnAuthor() {
127140
return DatasetAuthor.builder().authorName("Fred Blogs")
128-
.authorAffiliation("RSpace")
129-
.authorIdentifierScheme("ORCID")
130-
.authorIdentifier("1234-5678").build();
141+
.authorAffiliation("RSpace")
142+
.authorIdentifierScheme("ORCID")
143+
.authorIdentifier("1234-5678").build();
131144
}
132145

133146
}

0 commit comments

Comments
 (0)