Search in sources :

Example 1 with AttributeCharacterType

use of org.commongeoregistry.adapter.metadata.AttributeCharacterType in project geoprism-registry by terraframe.

the class XMLImporter method addAttributes.

private void addAttributes(Element root, ServerGeoObjectType type) {
    NodeList attributeList = root.getElementsByTagName("attributes");
    if (attributeList.getLength() > 0) {
        NodeList nList = attributeList.item(0).getChildNodes();
        for (int i = 0; i < nList.getLength(); i++) {
            Node nNode = nList.item(i);
            if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                Element elem = (Element) nNode;
                String code = elem.getAttribute("code");
                LocalizedValue label = this.getLabel(elem);
                LocalizedValue description = this.getDescription(elem);
                if (elem.getTagName().equals("text")) {
                    type.createAttributeType(new AttributeCharacterType(code, label, description, false, false, false));
                } else if (elem.getTagName().equals("boolean")) {
                    type.createAttributeType(new AttributeBooleanType(code, label, description, false, false, false));
                } else if (elem.getTagName().equals("integer")) {
                    type.createAttributeType(new AttributeIntegerType(code, label, description, false, false, false));
                } else if (elem.getTagName().equals("decimal")) {
                    AttributeFloatType attributeType = new AttributeFloatType(code, label, description, false, false, false);
                    attributeType.setPrecision(this.getPrecision(elem));
                    attributeType.setScale(this.getScale(elem));
                    type.createAttributeType(attributeType);
                } else if (elem.getTagName().equals("date")) {
                    type.createAttributeType(new AttributeDateType(code, label, description, false, false, false));
                } else if (elem.getTagName().equals("term")) {
                    AttributeTermType attributeType = new AttributeTermType(code, label, description, false, false, false);
                    attributeType = (AttributeTermType) type.createAttributeType(attributeType);
                    Term rootTerm = attributeType.getRootTerm();
                    this.createTermOptions(elem, rootTerm);
                } else if (elem.getTagName().equals("classification")) {
                    String rootCode = elem.getAttribute("root");
                    String classificationType = elem.getAttribute("classificationType");
                    AttributeClassificationType attributeType = new AttributeClassificationType(code, label, description, false, false, false);
                    attributeType.setRootTerm(new Term(rootCode, new LocalizedValue(""), new LocalizedValue("")));
                    attributeType.setClassificationType(classificationType);
                    attributeType = (AttributeClassificationType) type.createAttributeType(attributeType);
                }
            }
        }
    }
}
Also used : AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ServerElement(net.geoprism.registry.model.ServerElement) Element(org.w3c.dom.Element) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeCharacterType(org.commongeoregistry.adapter.metadata.AttributeCharacterType) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 2 with AttributeCharacterType

use of org.commongeoregistry.adapter.metadata.AttributeCharacterType in project geoprism-registry by terraframe.

the class BusinessObjectTest method setUpClassInRequest.

@Request
private static void setUpClassInRequest() {
    String code = "TEST_PROG";
    String orgCode = FastTestDataset.ORG_CGOV.getCode();
    String label = "Test Prog";
    JsonObject object = new JsonObject();
    object.addProperty(BusinessType.CODE, code);
    object.addProperty(BusinessType.ORGANIZATION, orgCode);
    object.add(BusinessType.DISPLAYLABEL, new LocalizedValue(label).toJSON());
    type = BusinessType.apply(object);
    attribute = type.createAttributeType(new AttributeCharacterType("testCharacter", new LocalizedValue("Test Character"), new LocalizedValue("Test True"), false, false, false));
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) JsonObject(com.google.gson.JsonObject) AttributeCharacterType(org.commongeoregistry.adapter.metadata.AttributeCharacterType) Request(com.runwaysdk.session.Request)

Example 3 with AttributeCharacterType

use of org.commongeoregistry.adapter.metadata.AttributeCharacterType in project geoprism-registry by terraframe.

the class DHIS2FeatureService method getDHIS2AttributeConfiguration.

@Request(RequestType.SESSION)
public JsonArray getDHIS2AttributeConfiguration(String sessionId, String dhis2SystemOid, String geoObjectTypeCode) {
    DHIS2ExternalSystem system = DHIS2ExternalSystem.get(dhis2SystemOid);
    JsonArray response = new JsonArray();
    ServerGeoObjectType got = ServerGeoObjectType.get(geoObjectTypeCode);
    Map<String, AttributeType> cgrAttrs = got.getAttributeMap();
    DHIS2TransportServiceIF dhis2;
    try {
        dhis2 = DHIS2ServiceFactory.buildDhis2TransportService(system);
    } catch (InvalidLoginException e) {
        LoginException cgrlogin = new LoginException(e);
        throw cgrlogin;
    } catch (HTTPException | UnexpectedResponseException | BadServerUriException | IllegalArgumentException e) {
        HttpError cgrhttp = new HttpError(e);
        throw cgrhttp;
    }
    final DHIS2OptionCache optionCache = new DHIS2OptionCache(dhis2);
    List<Attribute> dhis2Attrs = getDHIS2Attributes(dhis2);
    final String[] skipAttrs = new String[] { DefaultAttribute.GEOMETRY.getName(), DefaultAttribute.SEQUENCE.getName(), DefaultAttribute.TYPE.getName() };
    for (AttributeType cgrAttr : cgrAttrs.values()) {
        if (!ArrayUtils.contains(skipAttrs, cgrAttr.getName())) {
            JsonObject joAttr = new JsonObject();
            JsonObject joCgrAttr = new JsonObject();
            joCgrAttr.addProperty("name", cgrAttr.getName());
            joCgrAttr.addProperty("label", cgrAttr.getLabel().getValue());
            joCgrAttr.addProperty("type", cgrAttr.getType());
            joCgrAttr.addProperty("typeLabel", AttributeTypeMetadata.get().getTypeEnumDisplayLabel(cgrAttr.getType()));
            joAttr.add("cgrAttr", joCgrAttr);
            JsonArray jaStrategies = new JsonArray();
            List<DHIS2AttributeMapping> strategies = this.getMappingStrategies(cgrAttr);
            for (DHIS2AttributeMapping strategy : strategies) {
                jaStrategies.add(strategy.getClass().getName());
            }
            joAttr.add("attributeMappingStrategies", jaStrategies);
            JsonArray jaDhis2Attrs = new JsonArray();
            for (Attribute dhis2Attr : dhis2Attrs) {
                if (!dhis2Attr.getOrganisationUnitAttribute()) {
                    continue;
                }
                boolean valid = false;
                JsonObject jo = new JsonObject();
                if (cgrAttr instanceof AttributeBooleanType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.BOOLEAN) || dhis2Attr.getValueType().equals(ValueType.TRUE_ONLY))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeIntegerType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.INTEGER) || dhis2Attr.getValueType().equals(ValueType.INTEGER_POSITIVE) || dhis2Attr.getValueType().equals(ValueType.INTEGER_NEGATIVE) || dhis2Attr.getValueType().equals(ValueType.INTEGER_ZERO_OR_POSITIVE))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeFloatType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.NUMBER) || dhis2Attr.getValueType().equals(ValueType.UNIT_INTERVAL) || dhis2Attr.getValueType().equals(ValueType.PERCENTAGE))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeDateType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.DATE) || dhis2Attr.getValueType().equals(ValueType.DATETIME) || dhis2Attr.getValueType().equals(ValueType.TIME) || dhis2Attr.getValueType().equals(ValueType.AGE))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeTermType && dhis2Attr.getOptionSetId() != null) {
                    valid = true;
                    JsonArray jaDhis2Options = new JsonArray();
                    IntegratedOptionSet set = optionCache.getOptionSet(dhis2Attr.getOptionSetId());
                    SortedSet<Option> options = set.getOptions();
                    for (Option option : options) {
                        JsonObject joDhis2Option = new JsonObject();
                        joDhis2Option.addProperty("code", option.getCode());
                        joDhis2Option.addProperty("name", option.getName());
                        joDhis2Option.addProperty("id", option.getName());
                        jaDhis2Options.add(joDhis2Option);
                    }
                    jo.add("options", jaDhis2Options);
                } else if ((cgrAttr instanceof AttributeCharacterType || cgrAttr instanceof AttributeLocalType) && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.TEXT) || dhis2Attr.getValueType().equals(ValueType.LONG_TEXT) || dhis2Attr.getValueType().equals(ValueType.LETTER) || dhis2Attr.getValueType().equals(ValueType.PHONE_NUMBER) || dhis2Attr.getValueType().equals(ValueType.EMAIL) || dhis2Attr.getValueType().equals(ValueType.USERNAME) || dhis2Attr.getValueType().equals(ValueType.URL))) {
                    valid = true;
                }
                if (valid) {
                    jo.addProperty("dhis2Id", dhis2Attr.getId());
                    jo.addProperty("code", dhis2Attr.getCode());
                    jo.addProperty("name", dhis2Attr.getName());
                    jaDhis2Attrs.add(jo);
                }
            }
            joAttr.add("dhis2Attrs", jaDhis2Attrs);
            if (cgrAttr instanceof AttributeTermType) {
                JsonArray terms = new JsonArray();
                List<Term> children = ((AttributeTermType) cgrAttr).getTerms();
                for (Term child : children) {
                    JsonObject joTerm = new JsonObject();
                    joTerm.addProperty("label", child.getLabel().getValue());
                    joTerm.addProperty("code", child.getCode());
                    terms.add(joTerm);
                }
                joAttr.add("terms", terms);
            }
            response.add(joAttr);
        }
    }
    return response;
}
Also used : HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) Attribute(net.geoprism.dhis2.dhis2adapter.response.model.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) JsonObject(com.google.gson.JsonObject) DHIS2AttributeMapping(net.geoprism.registry.etl.DHIS2AttributeMapping) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) DHIS2TransportServiceIF(net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Term(org.commongeoregistry.adapter.Term) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) IntegratedOptionSet(net.geoprism.registry.etl.export.dhis2.DHIS2OptionCache.IntegratedOptionSet) JsonArray(com.google.gson.JsonArray) DHIS2OptionCache(net.geoprism.registry.etl.export.dhis2.DHIS2OptionCache) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) UnexpectedResponseException(net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException) Option(net.geoprism.dhis2.dhis2adapter.response.model.Option) HttpError(net.geoprism.registry.etl.export.HttpError) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) AttributeCharacterType(org.commongeoregistry.adapter.metadata.AttributeCharacterType) Request(com.runwaysdk.session.Request)

Example 4 with AttributeCharacterType

use of org.commongeoregistry.adapter.metadata.AttributeCharacterType in project geoprism-registry by terraframe.

the class BusinessTypeTest method testGetAttribute.

@Test
@Request
public void testGetAttribute() {
    String code = "TEST_PROG";
    String orgCode = FastTestDataset.ORG_CGOV.getCode();
    String label = "Test Prog";
    JsonObject object = new JsonObject();
    object.addProperty(BusinessType.CODE, code);
    object.addProperty(BusinessType.ORGANIZATION, orgCode);
    object.add(BusinessType.DISPLAYLABEL, new LocalizedValue(label).toJSON());
    BusinessType type = BusinessType.apply(object);
    try {
        AttributeCharacterType expected = new AttributeCharacterType("testCharacter", new LocalizedValue("Test Character"), new LocalizedValue("Test True"), false, false, false);
        type.createAttributeType(expected);
        AttributeType actual = type.getAttribute(expected.getName());
        Assert.assertTrue(actual instanceof AttributeCharacterType);
        Assert.assertEquals(expected.getName(), actual.getName());
        Assert.assertEquals(expected.getLabel().getValue(), actual.getLabel().getValue());
        Assert.assertEquals(expected.getIsDefault(), actual.getIsDefault());
    } finally {
        type.delete();
    }
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) BusinessType(net.geoprism.registry.BusinessType) JsonObject(com.google.gson.JsonObject) AttributeCharacterType(org.commongeoregistry.adapter.metadata.AttributeCharacterType) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

AttributeCharacterType (org.commongeoregistry.adapter.metadata.AttributeCharacterType)4 JsonObject (com.google.gson.JsonObject)3 Request (com.runwaysdk.session.Request)3 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)3 Term (org.commongeoregistry.adapter.Term)2 AttributeBooleanType (org.commongeoregistry.adapter.metadata.AttributeBooleanType)2 AttributeDateType (org.commongeoregistry.adapter.metadata.AttributeDateType)2 AttributeFloatType (org.commongeoregistry.adapter.metadata.AttributeFloatType)2 AttributeIntegerType (org.commongeoregistry.adapter.metadata.AttributeIntegerType)2 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)2 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)2 JsonArray (com.google.gson.JsonArray)1 BadServerUriException (net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException)1 HTTPException (net.geoprism.dhis2.dhis2adapter.exception.HTTPException)1 InvalidLoginException (net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException)1 UnexpectedResponseException (net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException)1 Attribute (net.geoprism.dhis2.dhis2adapter.response.model.Attribute)1 Option (net.geoprism.dhis2.dhis2adapter.response.model.Option)1 BusinessType (net.geoprism.registry.BusinessType)1 DHIS2AttributeMapping (net.geoprism.registry.etl.DHIS2AttributeMapping)1