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

first attempt to represent duo as json-schema #4643

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -209,7 +209,7 @@ public String loadStringFromClasspath(String name) throws Exception {

@Test
public void testMainUseCase() throws Exception {
bootstrapAndCreateOrganization();
bootstrapAndCreateOrganization("my.organization");
String[] schemasToRegister = { "pets/PetType.json", "pets/Pet.json", "pets/CatBreed.json", "pets/DogBreed.json",
"pets/Cat.json", "pets/Dog.json", "pets/PetPhoto.json" };
for (String fileName : schemasToRegister) {
Expand Down Expand Up @@ -252,11 +252,11 @@ public void testMainUseCase() throws Exception {
printJson(result);
}

void bootstrapAndCreateOrganization() throws RecoverableMessageException, InterruptedException {
void bootstrapAndCreateOrganization(String organizationName) throws RecoverableMessageException, InterruptedException {
jsonSchemaManager.truncateAll();
schemaBootstrap.bootstrapSynapseSchemas();
CreateOrganizationRequest createOrgRequest = new CreateOrganizationRequest();
createOrgRequest.setOrganizationName("my.organization");
createOrgRequest.setOrganizationName(organizationName);
organization = jsonSchemaManager.createOrganziation(adminUserInfo, createOrgRequest);
}

Expand Down Expand Up @@ -288,7 +288,7 @@ public void testGetValidationSchemaWorker() throws AssertionError, AsynchJobFail

@Test
public void testEntitySchemaValidation() throws Exception {
bootstrapAndCreateOrganization();
bootstrapAndCreateOrganization("my.organization");
String projectId = entityManager.createEntity(adminUserInfo, new Project(), null);
Project project = entityManager.getEntity(adminUserInfo, projectId, Project.class);

Expand Down Expand Up @@ -352,7 +352,7 @@ public void testCreateWithDryRun() throws Exception {

@Test
public void testEntitySchemaValidationWithBoolean() throws Exception {
bootstrapAndCreateOrganization();
bootstrapAndCreateOrganization("my.organization");
String projectId = entityManager.createEntity(adminUserInfo, new Project(), null);
Project project = entityManager.getEntity(adminUserInfo, projectId, Project.class);

Expand Down Expand Up @@ -397,7 +397,7 @@ public void testEntitySchemaValidationWithBoolean() throws Exception {
@Test
public void testNoSemanticVersionSchemaRevalidationWithSchemaChange() throws Exception {
// PLFM-6757
bootstrapAndCreateOrganization();
bootstrapAndCreateOrganization("my.organization");
String projectId = entityManager.createEntity(adminUserInfo, new Project(), null);
Project project = entityManager.getEntity(adminUserInfo, projectId, Project.class);

Expand Down Expand Up @@ -683,6 +683,91 @@ public void testValidationSchemaIndexWithReindexingAndRevalidation() throws Exce
waitForValidationResultsToBeNotFound(adminUserInfo, folderId);
}

@Test
public void testDuoSchema() throws Exception {
bootstrapAndCreateOrganization("ebispot.duo");
String[] schemasToRegister = { "schema/DUO/hmb.json", "schema/DUO/irb.json", "schema/DUO/duo.json"};
for (String fileName : schemasToRegister) {
JsonSchema schema = getSchemaFromClasspath(fileName);
registerSchema(schema);
}

JsonSchema validationSchema = jsonSchemaManager.getValidationSchema("ebispot.duo-duo");
assertNotNull(schemaBootstrap);
printJson(validationSchema);
assertNotNull(validationSchema.getDefinitions());
assertTrue(validationSchema.getDefinitions().containsKey("ebispot.duo-D0000006"));
assertTrue(validationSchema.getDefinitions().containsKey("ebispot.duo-D0000021"));


String validJsonFile = loadStringFromClasspath("schema/DUO/ValidDuoFile.json");
JSONObject validJson = new JSONObject(validJsonFile);
JsonSubject mockSubject = Mockito.mock(JsonSubject.class);
when(mockSubject.toJson()).thenReturn(validJson);
// this schema should be valid
ValidationResults result = jsonSchemaValidationManager.validate(validationSchema, mockSubject);
assertNotNull(result);
assertTrue(result.getIsValid());
}

@Test
public void testDuoSchemaAppliedAgainstValidFileJson() throws Exception {
bootstrapAndCreateOrganization("ebispot.duo");
jsonSchemaManager.createOrganziation(adminUserInfo, new CreateOrganizationRequest().setOrganizationName("some.project"));
String[] schemasToRegister = {
"schema/DUO/D0000001.json",
"schema/DUO/D0000004.json",
"schema/DUO/D0000006.json",
"schema/DUO/D0000007.json",
"schema/DUO/D0000011.json",
"schema/DUO/D0000012.json",
"schema/DUO/D0000015.json",
"schema/DUO/D0000016.json",
"schema/DUO/D0000018.json",
"schema/DUO/D0000019.json",
"schema/DUO/D0000020.json",
"schema/DUO/D0000021.json",
"schema/DUO/D0000022.json",
"schema/DUO/D0000024.json",
"schema/DUO/D0000025.json",
"schema/DUO/D0000026.json",
"schema/DUO/D0000027.json",
"schema/DUO/D0000028.json",
"schema/DUO/D0000029.json",
"schema/DUO/D0000042.json",
"schema/DUO/D0000043.json",
"schema/DUO/D0000044.json",
"schema/DUO/D0000045.json",
"schema/DUO/D0000046.json",
"schema/DUO/duo.json",
"schema/DUO/DuoMainStory.json",
};
for (String fileName : schemasToRegister) {
JsonSchema schema = getSchemaFromClasspath(fileName);
registerSchema(schema);
}

JsonSchema duoMain = jsonSchemaManager.getValidationSchema("ebispot.duo-duo");
assertNotNull(duoMain);
printJson(duoMain);

JsonSchema validationSchema = jsonSchemaManager.getValidationSchema("some.project-main");
assertNotNull(validationSchema);
printJson(validationSchema);

String[] validJsonFiles = { "schema/DUO/ValidSyn1.json", "schema/DUO/ValidSyn4.json" };
for (String schemaFile : validJsonFiles) {
String validJsonFile = loadStringFromClasspath(schemaFile);
JSONObject validJson = new JSONObject(validJsonFile);
JsonSubject mockSubject = Mockito.mock(JsonSubject.class);
when(mockSubject.toJson()).thenReturn(validJson);
// this schema should be valid
ValidationResults result = jsonSchemaValidationManager.validate(validationSchema, mockSubject);
assertNotNull(result);
assertTrue(result.getIsValid());
}
}

/**
* Wait for the validation results
*
Expand Down
6 changes: 6 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000001.json
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000001",
"title": "data use permission",
"description":"A data item that is used to indicate consent permissions for datasets and/or materials, and relates to the purposes for which datasets and/or material might be removed, stored or used."
}
12 changes: 12 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000004.json
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000004",
"title": "no restriction",
"properties": {
"NRES": {
"type": "boolean",
"description": "This data use permission indicates there is no restriction on use.",
"default": "false"
}
}
}
12 changes: 12 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000006.json
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000006",
"title": "health or medical or biomedical research",
"properties": {
"HMB": {
"type": "boolean",
"description": "This data use permission indicates that use is allowed for health/medical/biomedical purposes; does not include the study of population origins or ancestry.",
"default": "false"
}
}
}
33 changes: 33 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000007.json
@@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000007",
"title": "disease specific research",
"properties": {
"DS": {
"type": "boolean",
"description": "This data use permission indicates that use is allowed provided it is related to the specified disease.",
"default": "false"
}
},
"if": {
"properties": {
"DS": {
"const": true
}
}
},
"then": {
"properties": {
"DS_disease": {
"type": "string",
"description": "DUO recommends MONDO be used, to provide the basis for automated evaluation. For more information see https://github.com/EBISPOT/DUO/blob/master/MONDO_Overview.md",
"enum": [
"cancer",
"alzheimer",
"amnesia",
"..."
]
}
}
}
}
12 changes: 12 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000011.json
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000011",
"title": "population origins or ancestry research only",
"properties": {
"POA": {
"type": "boolean",
"description": "This data use permission indicates that use of the data is limited to the study of population origins or ancestry.",
"default": "false"
}
}
}
31 changes: 31 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000012.json
@@ -0,0 +1,31 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000012",
"title": "research specific restrictions",
"properties": {
"RS": {
"type": "boolean",
"description": "This data use modifier indicates that use is limited to studies of a certain research type.",
"default": "false"
}
},
"if": {
"properties": {
"RS": {
"const": true
}
}
},
"then": {
"properties": {
"RS_research_type": {
"type": "string",
"description": "...",
"enum": [
"cancer",
"..."
]
}
}
}
}
12 changes: 12 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000015.json
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000015",
"title": "no general methods research",
"properties": {
"NMDS": {
"type": "boolean",
"description": "This data use modifier indicates that use does not allow methods development research (e.g., development of software or algorithms).",
"default": "false"
}
}
}
12 changes: 12 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000016.json
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000016",
"title": "genetic studies only",
"properties": {
"GSO": {
"type": "boolean",
"description": "This data use modifier indicates that use is limited to genetic studies only (i.e., studies that include genotype research alone or both genotype and phenotype research, but not phenotype research exclusively)",
"default": "false"
}
}
}
12 changes: 12 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000018.json
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000018",
"title": "not for profit, non commercial use only",
"properties": {
"NPUNCU": {
"type": "boolean",
"description": "This data use modifier indicates that use of the data is limited to not-for-profit organizations and not-for-profit use, non-commercial use.",
"default": "false"
}
}
}
12 changes: 12 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000019.json
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000019",
"title": "publication required",
"properties": {
"PUB": {
"type": "boolean",
"description": "This data use modifier indicates that requestor agrees to make results of studies using the data available to the larger scientific community.",
"default": "false"
}
}
}
27 changes: 27 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000020.json
@@ -0,0 +1,27 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000020",
"title": "collaboration required",
"properties": {
"COL": {
"type": "boolean",
"description": "This data use modifier indicates that the requestor must agree to collaboration with the primary study investigator(s).",
"default": "false"
}
},
"if": {
"properties": {
"COL": {
"const": true
}
}
},
"then": {
"properties": {
"COL_PI": {
"type": "string",
"description": "This could be coupled with a string describing the primary study investigator(s)."
}
}
}
}
12 changes: 12 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000021.json
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000021",
"title": "ethics approval required",
"properties": {
"IRB": {
"type": "boolean",
"description": "This data use modifier indicates that the requestor must provide documentation of local IRB/ERB approval.",
"default": "false"
}
}
}
27 changes: 27 additions & 0 deletions services/workers/src/test/resources/schema/DUO/D0000022.json
@@ -0,0 +1,27 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ebispot.duo-D0000022",
"title": "geographical restriction",
"properties": {
"GS": {
"type": "boolean",
"description": "This data use modifier indicates that use is limited to within a specific geographic region.",
"default": "false"
}
},
"if": {
"properties": {
"GS": {
"const": true
}
}
},
"then": {
"properties": {
"GS_location": {
"type": "string",
"description": "This should be coupled with an ontology term describing the geographical location the restriction applies to."
}
}
}
}