Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8400 publish bug #8562

Merged
merged 24 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a5a6d1a
Merge branch 'develop' into 8400-publish-bug
sekmiller Feb 11, 2022
e03abaf
Merge branch 'develop' into 8400-publish-bug
sekmiller Feb 15, 2022
200ab70
Merge branch 'develop' into 8400-publish-bug
sekmiller Feb 16, 2022
19259fc
Merge branch 'develop' into 8400-publish-bug
sekmiller Feb 24, 2022
852f4bb
Merge branch 'develop' into 8400-publish-bug
sekmiller Feb 24, 2022
a1dfd6b
Merge branch 'develop' into 8400-publish-bug
sekmiller Feb 24, 2022
900d46f
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 3, 2022
96389df
#8400 add integration test for curation publish
sekmiller Mar 3, 2022
46d241b
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 15, 2022
a4d40f4
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 16, 2022
9e34b18
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 17, 2022
f42f647
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 21, 2022
9dae52c
#8400 test cv filter
sekmiller Mar 22, 2022
a9d6644
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 22, 2022
15dae72
#8400 revert cvv test
sekmiller Mar 23, 2022
0eee63f
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 23, 2022
b8d5484
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 30, 2022
e7a232b
#8400 fix variable metadata copy
sekmiller Mar 31, 2022
0d455d3
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 31, 2022
d56b028
Merge branch 'develop' into 8400-publish-bug
sekmiller Mar 31, 2022
b587642
#8400 revert testing change
sekmiller Mar 31, 2022
80ea9e7
#8400 revert to Copy var gps/metadata
sekmiller Mar 31, 2022
46ac308
Merge branch 'develop' into 8400-publish-bug
sekmiller Apr 8, 2022
05a06eb
Merge branch 'develop' into 8400-publish-bug
sekmiller Apr 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ public Dataset execute(CommandContext ctxt) throws CommandException {
dataFile.setRestricted(draftFmd.isRestricted());
publishedFmd.setProvFreeForm(draftFmd.getProvFreeForm());
publishedFmd.copyVariableMetadata(draftFmd.getVariableMetadatas());
Collection<VarGroup> vgl = publishedFmd.getVarGroups();
for (VarGroup vg : vgl) {
ctxt.em().remove(vg);
}
publishedFmd.copyVarGroups(draftFmd.getVarGroups());

}
Expand Down
156 changes: 156 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,39 @@
import com.jayway.restassured.path.xml.XmlPath;
import static edu.harvard.iq.dataverse.api.UtilIT.equalToCI;
import edu.harvard.iq.dataverse.authorization.groups.impl.builtin.AuthenticatedUsers;
import edu.harvard.iq.dataverse.datavariable.VarGroup;
import edu.harvard.iq.dataverse.datavariable.VariableMetadata;
import edu.harvard.iq.dataverse.datavariable.VariableMetadataDDIParser;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
import edu.harvard.iq.dataverse.util.json.JSONLDUtil;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObjectBuilder;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static javax.ws.rs.core.Response.Status.OK;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import static org.junit.Assert.assertEquals;
import org.hamcrest.CoreMatchers;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.CoreMatchers.nullValue;
import org.junit.AfterClass;
import org.junit.Assert;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.matchers.JUnitMatchers.containsString;
Expand Down Expand Up @@ -2587,4 +2597,150 @@ public void testFilesUnchangedAfterDatasetMetadataUpdate() throws IOException {

}

@Test
public void testCuratePublishedDatasetVersionCommand() throws IOException {
Response createUser = UtilIT.createRandomUser();
createUser.prettyPrint();
createUser.then().assertThat()
.statusCode(OK.getStatusCode());
String apiToken = UtilIT.getApiTokenFromResponse(createUser);
String username = UtilIT.getUsernameFromResponse(createUser);


Response createDataverse = UtilIT.createRandomDataverse(apiToken);
createDataverse.prettyPrint();
createDataverse.then().assertThat()
.statusCode(CREATED.getStatusCode());

String dataverseAlias = UtilIT.getAliasFromResponse(createDataverse);

Response createDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken);
createDataset.prettyPrint();
createDataset.then().assertThat()
.statusCode(CREATED.getStatusCode());

String datasetPid = JsonPath.from(createDataset.asString()).getString("data.persistentId");
Integer datasetId = JsonPath.from(createDataset.asString()).getInt("data.id");

Path pathtoScript = Paths.get(java.nio.file.Files.createTempDirectory(null) + File.separator + "run.sh");
java.nio.file.Files.write(pathtoScript, "#!/bin/bash\necho hello".getBytes());

JsonObjectBuilder json1 = Json.createObjectBuilder()
.add("description", "A script to reproduce results.")
.add("directoryLabel", "code");




String pathToFileThatGoesThroughIngest = "src/test/resources/sav/dct.sav";
Response uploadIngestableFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFileThatGoesThroughIngest, apiToken);
uploadIngestableFile.then().assertThat()
.statusCode(OK.getStatusCode());
uploadIngestableFile.prettyPrint();

String origFileId = JsonPath.from(uploadIngestableFile.body().asString()).getString("data.files[0].dataFile.id");

System.out.println("Orig file id " + origFileId);

logger.fine("Orig file id: " + origFileId);
assertNotNull(origFileId);
assertNotEquals("",origFileId);

// Give file time to ingest

assertTrue("Failed test if Ingest Lock exceeds max duration " + pathToFileThatGoesThroughIngest , UtilIT.sleepForLock(datasetId.longValue(), "Ingest", apiToken, UtilIT.MAXIMUM_INGEST_LOCK_DURATION));

Response origXml = UtilIT.getFileMetadata(origFileId, null, apiToken);
assertEquals(200, origXml.getStatusCode());


String stringOrigXml = origXml.getBody().prettyPrint();

InputStream variableData = origXml.body().asInputStream();

Map<Long, VariableMetadata> mapVarToVarMet = new HashMap<Long, VariableMetadata>();
Map<Long,VarGroup> varGroupMap = new HashMap<Long, VarGroup>();
try {
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader xmlr = factory.createXMLStreamReader(variableData);
VariableMetadataDDIParser vmdp = new VariableMetadataDDIParser();

vmdp.processDataDscr(xmlr, mapVarToVarMet, varGroupMap);

} catch (XMLStreamException e) {
logger.warning(e.getMessage());
assertEquals(0,1);
}


//Test here
String updatedContent = "";
try {
updatedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/xml/dct.xml")));
} catch (IOException e) {
logger.warning(e.getMessage());
assertEquals(0,1);
}
Long replV1168 = 0L;
Long replV1169 = 0L;
Long replV1170 = 0L;
int numberVariables = 0;
for (VariableMetadata var : mapVarToVarMet.values()) {
if (var.getLabel().equals("gender")) {
replV1170 = var.getDataVariable().getId();
numberVariables = numberVariables +1;
} else if (var.getLabel().equals("weight")) {
replV1168 = var.getDataVariable().getId();
numberVariables = numberVariables +1;
} else if (var.getLabel().equals("age_rollup")) {
replV1169 = var.getDataVariable().getId();
numberVariables = numberVariables +1;
}
}
assertEquals(3, numberVariables);

updatedContent = updatedContent.replaceAll("v1168", "v" + replV1168 );
updatedContent = updatedContent.replaceAll("v1169", "v" + replV1169 );
updatedContent = updatedContent.replaceAll("v1170", "v" + replV1170 );

//edit draft vesrsion
Response editDDIResponse = UtilIT.editDDI(updatedContent, origFileId, apiToken);

editDDIResponse.prettyPrint();
assertEquals(200, editDDIResponse.getStatusCode());



UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode());
UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken).then().assertThat().statusCode(OK.getStatusCode());

Response getDatasetJsonBeforeUpdate = UtilIT.nativeGet(datasetId, apiToken);
getDatasetJsonBeforeUpdate.prettyPrint();
getDatasetJsonBeforeUpdate.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.latestVersion.files[0].label", equalTo("dct.tab"));

String pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-update-metadata.json";
Response updateTitle = UtilIT.updateDatasetMetadataViaNative(datasetPid, pathToJsonFile, apiToken);
updateTitle.prettyPrint();
updateTitle.then().assertThat()
.statusCode(OK.getStatusCode());

// shouldn't be able to update current unless you're a super user

UtilIT.publishDatasetViaNativeApi(datasetId, "updatecurrent", apiToken).then().assertThat().statusCode(FORBIDDEN.getStatusCode());

Response makeSuperUser = UtilIT.makeSuperUser(username);

//should work after making super user

UtilIT.publishDatasetViaNativeApi(datasetId, "updatecurrent", apiToken).then().assertThat().statusCode(OK.getStatusCode());

Response getDatasetJsonAfterUpdate = UtilIT.nativeGet(datasetId, apiToken);
getDatasetJsonAfterUpdate.prettyPrint();
getDatasetJsonAfterUpdate.then().assertThat()
.statusCode(OK.getStatusCode());

}

}