Search in sources :

Example 61 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project oxTrust by GluuFederation.

the class SchemaTypeGroupSerializer method serialize.

@Override
public void serialize(Group group, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    log.info(" serialize() ");
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        JsonNode rootNode = mapper.convertValue(group, JsonNode.class);
        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
            if (rootNodeEntry.getValue() instanceof ObjectNode) {
            // Definitely maybe in the near future
            } else if (rootNodeEntry.getValue() instanceof ArrayNode) {
                AttributeHolder arrayNodeAttributeHolder = new AttributeHolder();
                arrayNodeAttributeHolder.setName(rootNodeEntry.getKey());
                if (rootNodeEntry.getKey().equalsIgnoreCase("members")) {
                    arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list; using sub-attributes in a query filter is not supported (cross-querying)");
                    arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                    List<String> referenceTypes = new ArrayList<String>();
                    referenceTypes.add("User");
                    arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
                } else {
                    arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list");
                    arrayNodeAttributeHolder.setCaseExact(Boolean.FALSE);
                }
                arrayNodeAttributeHolder.setRequired(Boolean.FALSE);
                arrayNodeAttributeHolder.setMultiValued(Boolean.TRUE);
                if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
                    arrayNodeAttributeHolder.setUniqueness("server");
                    arrayNodeAttributeHolder.setType("string");
                    arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                    arrayNodeAttributeHolder.setMutability("readOnly");
                    arrayNodeAttributeHolder.setReturned("always");
                } else {
                    arrayNodeAttributeHolder.setType("complex");
                }
                List<AttributeHolder> arrayNodeMapAttributeHolders = new ArrayList<AttributeHolder>();
                Iterator<JsonNode> arrayNodeIterator = rootNodeEntry.getValue().getElements();
                while (arrayNodeIterator.hasNext()) {
                    JsonNode jsonNode = arrayNodeIterator.next();
                    Iterator<Map.Entry<String, JsonNode>> arrayNodeMapIterator = jsonNode.getFields();
                    while (arrayNodeMapIterator.hasNext()) {
                        Map.Entry<String, JsonNode> arrayNodeMapRootNodeEntry = arrayNodeMapIterator.next();
                        AttributeHolder arrayNodeMapAttributeHolder = new AttributeHolder();
                        if (rootNodeEntry.getKey().equalsIgnoreCase("members") && arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("reference")) {
                            arrayNodeMapAttributeHolder.setName("$ref");
                        } else {
                            arrayNodeMapAttributeHolder.setName(arrayNodeMapRootNodeEntry.getKey());
                        }
                        arrayNodeMapAttributeHolder.setType("string");
                        arrayNodeMapAttributeHolder.setDescription(arrayNodeMapRootNodeEntry.getKey());
                        if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("value") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("type")) {
                            arrayNodeMapAttributeHolder.setRequired(Boolean.TRUE);
                        } else {
                            arrayNodeMapAttributeHolder.setRequired(Boolean.FALSE);
                        }
                        arrayNodeMapAttributeHolders.add(arrayNodeMapAttributeHolder);
                    }
                    arrayNodeAttributeHolder.setSubAttributes(arrayNodeMapAttributeHolders);
                    attributeHolders.add(arrayNodeAttributeHolder);
                }
            } else {
                if (!rootNodeEntry.getKey().equalsIgnoreCase("externalId")) {
                    AttributeHolder attributeHolder = new AttributeHolder();
                    attributeHolder.setName(rootNodeEntry.getKey());
                    if (rootNodeEntry.getValue().isBoolean()) {
                        attributeHolder.setType("boolean");
                    } else {
                        attributeHolder.setType("string");
                    }
                    attributeHolder.setDescription(rootNodeEntry.getKey());
                    attributeHolder.setRequired(Boolean.FALSE);
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id")) {
                        attributeHolder.setUniqueness("server");
                        attributeHolder.setCaseExact(Boolean.TRUE);
                        attributeHolder.setMutability("readOnly");
                        attributeHolder.setReturned("always");
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
                        attributeHolder.setReturned("always");
                    }
                    attributeHolders.add(attributeHolder);
                }
            }
        }
        GroupCoreSchema groupCoreSchema = (GroupCoreSchema) schemaType;
        groupCoreSchema.setAttributeHolders(attributeHolders);
        schemaType = groupCoreSchema;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Unexpected processing error; please check the Group class structure.");
    }
}
Also used : AttributeHolder(org.gluu.oxtrust.model.scim2.schema.AttributeHolder) ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) GroupCoreSchema(org.gluu.oxtrust.model.scim2.schema.core.GroupCoreSchema) IOException(java.io.IOException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(org.codehaus.jackson.node.ArrayNode) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 62 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project dhis2-core by dhis2.

the class AttributeValueServiceTest method testGetJsonAttributeValues.

@Test
public void testGetJsonAttributeValues() throws Exception {
    DataElement dataElementA = createDataElement('A');
    manager.save(dataElementA);
    Attribute attribute1 = new Attribute("attribute1", ValueType.TEXT);
    attribute1.setDataElementAttribute(true);
    attributeService.addAttribute(attribute1);
    AttributeValue av = new AttributeValue("value1", attribute1);
    attributeService.addAttributeValue(dataElementA, av);
    manager.update(dataElementA);
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    node.put("id", attribute1.getId());
    node.put("value", "updatedvalue1");
    List<String> jsonValues = new ArrayList<>();
    jsonValues.add(node.toString());
    attributeService.updateAttributeValues(dataElementA, jsonValues);
    av = attributeService.getAttributeValue(av.getId());
    assertEquals("updatedvalue1", av.getValue());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayList(java.util.ArrayList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) DhisSpringTest(org.hisp.dhis.DhisSpringTest) Test(org.junit.Test)

Example 63 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project openmrs-module-mirebalais by PIH.

the class CustomAppLoaderTest method shouldCreateSection.

@Test
public void shouldCreateSection() {
    ObjectNode section = CustomAppLoaderUtil.section("someSectionId", "someSectionLabel", CustomAppLoaderUtil.question("someQuestionId", "someQuestionLegend", CustomAppLoaderUtil.field("someField", "someLabel", "someType", "", "", "")), CustomAppLoaderUtil.question("anotherQuestionId", "anotherQuestionLegend", CustomAppLoaderUtil.field("anotherField", "anotherLabel", "anotherType", "", "", "")));
    assertThat(section.get("id").getTextValue(), is("someSectionId"));
    assertThat(section.get("label").getTextValue(), is("someSectionLabel"));
    ObjectNode question1 = (ObjectNode) section.get("questions").get(0);
    ObjectNode question2 = (ObjectNode) section.get("questions").get(1);
    assertThat(question1.get("id").getTextValue(), is("someQuestionId"));
    assertThat(question1.get("legend").getTextValue(), is("someQuestionLegend"));
    assertThat(question2.get("id").getTextValue(), is("anotherQuestionId"));
    assertThat(question2.get("legend").getTextValue(), is("anotherQuestionLegend"));
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) Test(org.junit.Test)

Example 64 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project openmrs-module-mirebalais by PIH.

the class CustomAppLoaderTest method shouldCreateQuestion.

@Test
public void shouldCreateQuestion() {
    ObjectNode question = CustomAppLoaderUtil.question("someQuestionId", "someQuestionLegend", CustomAppLoaderUtil.field("phoneNumber", "registrationapp.patient.phone.question", "personAttribute", "14d4f066-15f5-102d-96e4-000c29c2a5d7", "uicommons", "field/text"), CustomAppLoaderUtil.field("anotherField", "anotherLabel", "anotherType", "", "", "", "someClass", "anotherClass"));
    assertThat(question.get("id").getTextValue(), is("someQuestionId"));
    assertThat(question.get("legend").getTextValue(), is("someQuestionLegend"));
    ObjectNode field1 = (ObjectNode) question.get("fields").get(0);
    ObjectNode field2 = (ObjectNode) question.get("fields").get(1);
    assertThat(field1.get("formFieldName").getTextValue(), is("phoneNumber"));
    assertThat(field1.get("label").getTextValue(), is("registrationapp.patient.phone.question"));
    assertThat(field1.get("type").getTextValue(), is("personAttribute"));
    assertThat(field1.get("uuid").getTextValue(), is("14d4f066-15f5-102d-96e4-000c29c2a5d7"));
    assertThat(field1.get("widget").get("providerName").getTextValue(), is("uicommons"));
    assertThat(field1.get("widget").get("fragmentId").getTextValue(), is("field/text"));
    assertThat(field2.get("formFieldName").getTextValue(), is("anotherField"));
    assertThat(field2.get("label").getTextValue(), is("anotherLabel"));
    assertThat(field2.get("type").getTextValue(), is("anotherType"));
    assertThat(field2.get("cssClasses").get(0).getTextValue(), is("someClass"));
    assertThat(field2.get("cssClasses").get(1).getTextValue(), is("anotherClass"));
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) Test(org.junit.Test)

Example 65 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project openmrs-module-coreapps by openmrs.

the class EncounterDiagnosesTagHandlerComponentTest method testHandleSubmissionHandlesValidSubmissionEnteringForm.

@Test
public void testHandleSubmissionHandlesValidSubmissionEnteringForm() throws Exception {
    final int codedConceptId = 11;
    ObjectMapper jackson = new ObjectMapper();
    ArrayNode json = jackson.createArrayNode();
    ObjectNode diagnosisNode = json.addObject();
    diagnosisNode.put("certainty", "PRESUMED");
    diagnosisNode.put("order", "PRIMARY");
    diagnosisNode.put("diagnosis", CodedOrFreeTextAnswer.CONCEPT_PREFIX + codedConceptId);
    final String jsonToSubmit = jackson.writeValueAsString(json);
    final DiagnosisMetadata dmd = emrApiProperties.getDiagnosisMetadata();
    final Date date = new Date();
    new RegressionTestHelper() {

        @Override
        public String getXmlDatasetPath() {
            return "";
        }

        @Override
        public String getFormName() {
            return "encounterDiagnosesSimpleForm";
        }

        @Override
        public Map<String, Object> getFormEntrySessionAttributes() {
            Map<String, Object> attributes = new HashMap<String, Object>();
            attributes.put("uiUtils", new TestUiUtils() {

                @Override
                public String includeFragment(String providerName, String fragmentId, Map<String, Object> config) throws PageAction {
                    return "[[ included fragment " + providerName + "." + fragmentId + " here ]]";
                }
            });
            return attributes;
        }

        @Override
        public String[] widgetLabels() {
            return new String[] { "Date:", "Location:", "Provider:", "Encounter Type:" };
        }

        @Override
        public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
            request.setParameter(widgets.get("Date:"), dateAsString(date));
            request.setParameter(widgets.get("Location:"), "2");
            request.setParameter(widgets.get("Provider:"), "1");
            request.setParameter(widgets.get("Encounter Type:"), "1");
            request.setParameter("encounterDiagnoses", jsonToSubmit);
        }

        @Override
        public void testResults(SubmissionResults results) {
            results.assertNoErrors();
            results.assertEncounterCreated();
            results.assertProvider(1);
            results.assertLocation(2);
            results.assertEncounterType(1);
            results.assertObsCreatedCount(1);
            results.assertObsGroupCreated(dmd.getDiagnosisSetConcept().getConceptId(), dmd.getDiagnosisCertaintyConcept().getId(), dmd.getConceptFor(Diagnosis.Certainty.PRESUMED), dmd.getDiagnosisOrderConcept().getId(), dmd.getConceptFor(Diagnosis.Order.PRIMARY), dmd.getCodedDiagnosisConcept().getId(), Context.getConceptService().getConcept(codedConceptId));
        }
    }.run();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) TestUiUtils(org.openmrs.module.appui.TestUiUtils) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DiagnosisMetadata(org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata) Date(java.util.Date) ArrayNode(org.codehaus.jackson.node.ArrayNode) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) Test(org.junit.Test) BaseModuleWebContextSensitiveTest(org.openmrs.web.test.BaseModuleWebContextSensitiveTest)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)29 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)16 Produces (javax.ws.rs.Produces)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)5 JsonFactory (org.codehaus.jackson.JsonFactory)5 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Span (org.apache.stanbol.enhancer.nlp.model.Span)4 DatasetImpl (org.eol.globi.service.DatasetImpl)4 Date (java.util.Date)3 TaskDriver (org.apache.helix.task.TaskDriver)3 WorkflowConfig (org.apache.helix.task.WorkflowConfig)3