use of javax.json.JsonReader in project dataverse by IQSS.
the class Admin method convertUserFromBcryptToSha1.
/**
* This method is used by an integration test in UsersIT.java to exercise
* bug https://github.com/IQSS/dataverse/issues/3287 . Not for use by users!
*/
@Path("convertUserFromBcryptToSha1")
@POST
public Response convertUserFromBcryptToSha1(String json) {
JsonReader jsonReader = Json.createReader(new StringReader(json));
JsonObject object = jsonReader.readObject();
jsonReader.close();
BuiltinUser builtinUser = builtinUserService.find(new Long(object.getInt("builtinUserId")));
// password is "sha-1Pass", 0 means SHA-1
builtinUser.updateEncryptedPassword("4G7xxL9z11/JKN4jHPn4g9iIQck=", 0);
BuiltinUser savedUser = builtinUserService.save(builtinUser);
return ok("foo: " + savedUser);
}
use of javax.json.JsonReader in project dataverse by IQSS.
the class DataCaptureModuleServiceBeanIT method testUploadRequestAndScriptRequest.
@Test
public void testUploadRequestAndScriptRequest() throws InterruptedException, DataCaptureModuleException {
// The DCM Vagrant box runs on port 8888: https://github.com/sbgrid/data-capture-module/blob/master/Vagrantfile
String dcmVagrantUrl = "http://localhost:8888";
// The DCM mock runs on port 5000: https://github.com/sbgrid/data-capture-module/blob/master/doc/mock.md
String dcmMockUrl = "http://localhost:5000";
String dcmBaseUrl = dcmMockUrl;
DataCaptureModuleServiceBean dataCaptureModuleServiceBean = new DataCaptureModuleServiceBean();
// Step 1: Upload request
AuthenticatedUser authenticatedUser = makeAuthenticatedUser("Lauren", "Ipsum");
Dataset dataset = new Dataset();
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
long timeInMillis = calendar.getTimeInMillis();
String ident = Long.toString(timeInMillis);
dataset.setIdentifier(ident);
String jsonString = DataCaptureModuleUtil.generateJsonForUploadRequest(authenticatedUser, dataset).toString();
logger.info("jsonString: " + jsonString);
UploadRequestResponse uploadRequestResponse = dataCaptureModuleServiceBean.requestRsyncScriptCreation(jsonString, dcmBaseUrl + DataCaptureModuleServiceBean.uploadRequestPath);
System.out.println("out: " + uploadRequestResponse.getResponse());
assertEquals(200, uploadRequestResponse.getHttpStatusCode());
String uploadRequestResponseString = uploadRequestResponse.getResponse();
JsonReader jsonReader = Json.createReader(new StringReader((String) uploadRequestResponseString));
JsonObject jsonObject = jsonReader.readObject();
assertEquals("OK", jsonObject.getString("status"));
// If you comment this out, expect to see a 404 when you try to download the script.
sleep(DataCaptureModuleServiceBean.millisecondsToSleepBetweenUploadRequestAndScriptRequestCalls);
// Step 2: Script request.
ScriptRequestResponse scriptRequestResponseGood = dataCaptureModuleServiceBean.retreiveRequestedRsyncScript(dataset.getIdentifier(), dcmBaseUrl + DataCaptureModuleServiceBean.scriptRequestPath);
System.out.println("script: " + scriptRequestResponseGood.getScript());
assertNotNull(scriptRequestResponseGood.getScript());
assertTrue(scriptRequestResponseGood.getScript().startsWith("#!"));
}
use of javax.json.JsonReader in project dataverse by IQSS.
the class SchemaDotOrgExporterTest method testExportDataset.
/**
* Test of exportDataset method, of class SchemaDotOrgExporter.
*/
@Test
public void testExportDataset() throws Exception {
System.out.println("exportDataset");
File datasetVersionJson = new File("src/test/resources/json/dataset-finch1.json");
String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));
JsonReader jsonReader1 = Json.createReader(new StringReader(datasetVersionAsJson));
JsonObject json1 = jsonReader1.readObject();
JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, null);
DatasetVersion version = jsonParser.parseDatasetVersion(json1.getJsonObject("datasetVersion"));
version.setVersionState(DatasetVersion.VersionState.RELEASED);
SimpleDateFormat dateFmt = new SimpleDateFormat("yyyyMMdd");
Date publicationDate = dateFmt.parse("19551105");
version.setReleaseTime(publicationDate);
version.setVersionNumber(1l);
// TODO: It might be nice to test TermsOfUseAndAccess some day
version.setTermsOfUseAndAccess(null);
Dataset dataset = new Dataset();
dataset.setProtocol("doi");
dataset.setAuthority("myAuthority");
dataset.setIdentifier("myIdentifier");
version.setDataset(dataset);
Dataverse dataverse = new Dataverse();
dataverse.setName("LibraScholar");
dataset.setOwner(dataverse);
System.setProperty(SITE_URL, "https://librascholar.org");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
schemaDotOrgExporter.exportDataset(version, json1, byteArrayOutputStream);
String jsonLd = byteArrayOutputStream.toString();
System.out.println("schema.org JSON-LD: " + JsonUtil.prettyPrint(jsonLd));
JsonReader jsonReader2 = Json.createReader(new StringReader(jsonLd));
JsonObject json2 = jsonReader2.readObject();
assertEquals("http://schema.org", json2.getString("@context"));
assertEquals("Dataset", json2.getString("@type"));
assertEquals("https://doi.org/myAuthority/myIdentifier", json2.getString("identifier"));
assertEquals("Darwin's Finches", json2.getString("name"));
assertEquals("Finch, Fiona", json2.getJsonArray("author").getJsonObject(0).getString("name"));
assertEquals("Birds Inc.", json2.getJsonArray("author").getJsonObject(0).getString("affiliation"));
assertEquals("1955-11-05", json2.getString("dateModified"));
assertEquals("1", json2.getString("version"));
assertEquals("Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.", json2.getString("description"));
assertEquals("Medicine, Health and Life Sciences", json2.getJsonArray("keywords").getString(0));
assertEquals("https://schema.org/version/3.3", json2.getString("schemaVersion"));
assertEquals("DataCatalog", json2.getJsonObject("includedInDataCatalog").getString("@type"));
assertEquals("LibraScholar", json2.getJsonObject("includedInDataCatalog").getString("name"));
assertEquals("https://librascholar.org", json2.getJsonObject("includedInDataCatalog").getString("url"));
assertEquals("Organization", json2.getJsonObject("provider").getString("@type"));
assertEquals("Dataverse", json2.getJsonObject("provider").getString("name"));
}
use of javax.json.JsonReader in project dataverse by IQSS.
the class AbstractApiBeanTest method testMessagesNoJsonObject.
@Test
public void testMessagesNoJsonObject() {
String message = "myMessage";
Response response = sut.ok(message);
JsonReader jsonReader = Json.createReader(new StringReader((String) response.getEntity().toString()));
JsonObject jsonObject = jsonReader.readObject();
Map<String, Boolean> config = new HashMap<>();
config.put(JsonGenerator.PRETTY_PRINTING, true);
JsonWriterFactory jwf = Json.createWriterFactory(config);
StringWriter sw = new StringWriter();
try (JsonWriter jsonWriter = jwf.createWriter(sw)) {
jsonWriter.writeObject(jsonObject);
}
logger.info(sw.toString());
assertEquals(message, jsonObject.getJsonObject("data").getString("message"));
}
use of javax.json.JsonReader in project solr-document-store by DBCDK.
the class AsyncJobWebSocketServer method message.
@OnMessage
public void message(String message, Session session) {
log.info("Recieved message: {}", message);
try (JsonReader reader = Json.createReader(new StringReader(message))) {
JsonObject jsonMessage = reader.readObject();
String uuid = jsonMessage.getString("uuid");
switch(jsonMessage.getString("type")) {
case "Requesting subscription":
sessionHandler.subscribe(session, uuid);
break;
case "Requesting unsubscription":
sessionHandler.unsubscribe(session, uuid);
break;
}
}
}
Aggregations