use of org.commongeoregistry.adapter.metadata.AttributeFloatType 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);
}
}
}
}
}
use of org.commongeoregistry.adapter.metadata.AttributeFloatType in project geoprism-registry by terraframe.
the class MasterListVersion method createMdAttributeFromAttributeType.
protected static void createMdAttributeFromAttributeType(TableMetadata metadata, AttributeType attributeType, ServerGeoObjectType type, Collection<Locale> locales) {
MdBusiness mdBusiness = metadata.getMdBusiness();
if (!(attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType || attributeType instanceof AttributeLocalType)) {
MdAttributeConcrete mdAttribute = null;
if (attributeType.getType().equals(AttributeCharacterType.TYPE)) {
mdAttribute = new MdAttributeCharacter();
MdAttributeCharacter mdAttributeCharacter = (MdAttributeCharacter) mdAttribute;
mdAttributeCharacter.setDatabaseSize(MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
} else if (attributeType.getType().equals(AttributeDateType.TYPE)) {
mdAttribute = new MdAttributeDateTime();
} else if (attributeType.getType().equals(AttributeIntegerType.TYPE)) {
mdAttribute = new MdAttributeLong();
} else if (attributeType.getType().equals(AttributeFloatType.TYPE)) {
AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
mdAttribute = new MdAttributeDouble();
mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
} else if (attributeType.getType().equals(AttributeBooleanType.TYPE)) {
mdAttribute = new MdAttributeBoolean();
} else {
throw new UnsupportedOperationException("Unsupported type [" + attributeType.getType() + "]");
}
mdAttribute.setAttributeName(attributeType.getName());
LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
mdAttribute.setDefiningMdClass(mdBusiness);
mdAttribute.apply();
} else if (attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType) {
MdAttributeCharacter cloneAttribute = new MdAttributeCharacter();
cloneAttribute.setValue(MdAttributeConcreteInfo.NAME, attributeType.getName());
cloneAttribute.setValue(MdAttributeCharacterInfo.SIZE, "255");
cloneAttribute.addIndexType(MdAttributeIndices.NON_UNIQUE_INDEX);
LocalizedValueConverter.populate(cloneAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(cloneAttribute.getDescription(), attributeType.getDescription());
cloneAttribute.setDefiningMdClass(mdBusiness);
cloneAttribute.apply();
metadata.addPair(cloneAttribute, cloneAttribute);
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
metadata.addPair(mdAttributeDefaultLocale, cloneAttribute);
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
metadata.addPair(mdAttributeLocale, cloneAttribute);
}
// MdAttributeUUID mdAttributeOid = new MdAttributeUUID();
// mdAttributeOid.setValue(MdAttributeConcreteInfo.NAME,
// attributeType.getName() + "Oid");
// AbstractBuilder.populate(mdAttributeOid.getDisplayLabel(),
// attributeType.getLabel());
// AbstractBuilder.populate(mdAttributeOid.getDescription(),
// attributeType.getDescription());
// mdAttributeOid.setDefiningMdClass(mdBusiness);
// mdAttributeOid.apply();
} else if (attributeType instanceof AttributeLocalType) {
boolean isDisplayLabel = attributeType.getName().equals(DefaultAttribute.DISPLAY_LABEL.getName());
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
}
}
}
use of org.commongeoregistry.adapter.metadata.AttributeFloatType in project geoprism-registry by terraframe.
the class AttributeTypeConverter method build.
public AttributeType build(MdAttributeConcreteDAOIF mdAttribute) {
Locale locale = Session.getCurrentLocale();
String attributeName = mdAttribute.definesAttribute();
LocalizedValue displayLabel = AttributeTypeConverter.convert(mdAttribute.getDisplayLabel(locale), mdAttribute.getDisplayLabels());
LocalizedValue description = AttributeTypeConverter.convert(mdAttribute.getDescription(locale), mdAttribute.getDescriptions());
boolean required = mdAttribute.isRequired();
boolean unique = mdAttribute.isUnique();
boolean isChangeOverTime = true;
DefaultAttribute defaultAttr = DefaultAttribute.getByAttributeName(attributeName);
if (defaultAttr != null) {
isChangeOverTime = defaultAttr.isChangeOverTime();
}
if (mdAttribute instanceof MdAttributeBooleanDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeBooleanType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeLocalDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeLocalType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeCharacterDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeCharacterType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeDateDAOIF || mdAttribute instanceof MdAttributeDateTimeDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeDateType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeDecDAOIF) {
MdAttributeDecDAOIF mdAttributeDec = (MdAttributeDecDAOIF) mdAttribute;
AttributeFloatType attributeType = (AttributeFloatType) AttributeType.factory(attributeName, displayLabel, description, AttributeFloatType.TYPE, required, unique, isChangeOverTime);
attributeType.setPrecision(Integer.parseInt(mdAttributeDec.getLength()));
attributeType.setScale(Integer.parseInt(mdAttributeDec.getDecimal()));
return attributeType;
} else if (mdAttribute instanceof MdAttributeIntegerDAOIF || mdAttribute instanceof MdAttributeLongDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeIntegerType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeClassificationDAOIF) {
MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
AttributeClassificationType attributeType = (AttributeClassificationType) AttributeType.factory(attributeName, displayLabel, description, AttributeClassificationType.TYPE, required, unique, isChangeOverTime);
attributeType.setClassificationType(mdClassification.getValue(MdClassificationInfo.TYPE_NAME));
String rootOid = ((MdAttributeClassificationDAOIF) mdAttribute).getValue(MdAttributeClassificationInfo.ROOT);
if (rootOid != null && rootOid.length() > 0) {
ClassificationType type = new ClassificationType(mdClassification);
Classification classification = Classification.getByOid(type, rootOid);
attributeType.setRootTerm(classification.toTerm());
}
return attributeType;
} else if (mdAttribute instanceof MdAttributeEnumerationDAOIF || mdAttribute instanceof MdAttributeTermDAOIF) {
AttributeTermType attributeType = (AttributeTermType) AttributeType.factory(attributeName, displayLabel, description, AttributeTermType.TYPE, required, unique, isChangeOverTime);
if (mdAttribute instanceof MdAttributeTermDAOIF) {
List<RelationshipDAOIF> rels = ((MdAttributeTermDAOIF) mdAttribute).getAllAttributeRoots();
if (rels.size() > 0) {
RelationshipDAOIF rel = rels.get(0);
BusinessDAO classy = (BusinessDAO) rel.getChild();
TermConverter termBuilder = new TermConverter(classy.getKey());
Term adapterTerm = termBuilder.build();
attributeType.setRootTerm(adapterTerm);
} else {
throw new ProgrammingErrorException("Expected an attribute root on MdAttribute [" + mdAttribute.getKey() + "].");
}
} else {
throw new ProgrammingErrorException("Enum attributes are not supported at this time.");
}
return attributeType;
}
throw new UnsupportedOperationException("Unsupported attribute type [" + mdAttribute.getClass().getSimpleName() + "]");
}
use of org.commongeoregistry.adapter.metadata.AttributeFloatType 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;
}
use of org.commongeoregistry.adapter.metadata.AttributeFloatType in project geoprism-registry by terraframe.
the class ServerGeoObjectType method updateMdAttributeFromAttributeType.
/**
* Creates an {@link MdAttributeConcrete} for the given {@link MdBusiness}
* from the given {@link AttributeType}
*
* @pre assumes no attribute has been defined on the type with the given name.
*
* @param mdBusiness
* Type to receive attribute definition
* @param attributeType
* newly defined attribute
*
* @return {@link AttributeType}
*/
@Transaction
public static MdAttributeConcrete updateMdAttributeFromAttributeType(MdClass mdClass, AttributeType attributeType) {
MdAttributeConcreteDAOIF mdAttributeConcreteDAOIF = getMdAttribute(mdClass, attributeType.getName());
if (mdAttributeConcreteDAOIF != null) {
// Get the type safe version
MdAttributeConcrete mdAttribute = (MdAttributeConcrete) BusinessFacade.get(mdAttributeConcreteDAOIF);
mdAttribute.lock();
try {
// The name cannot be updated
// mdAttribute.setAttributeName(attributeType.getName());
LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
if (attributeType instanceof AttributeFloatType) {
// Refresh the terms
AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
} else if (attributeType instanceof AttributeClassificationType) {
MdAttributeClassification mdAttributeTerm = (MdAttributeClassification) mdAttribute;
AttributeClassificationType attributeClassificationType = (AttributeClassificationType) attributeType;
String classificationTypeCode = attributeClassificationType.getClassificationType();
ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
Term root = attributeClassificationType.getRootTerm();
if (root != null) {
Classification classification = Classification.get(classificationType, root.getCode());
mdAttributeTerm.setValue(MdAttributeClassification.ROOT, classification.getOid());
}
}
mdAttribute.apply();
} finally {
mdAttribute.unlock();
}
if (attributeType instanceof AttributeTermType) {
// Refresh the terms
AttributeTermType attributeTermType = (AttributeTermType) attributeType;
org.commongeoregistry.adapter.Term getRootTerm = attributeTermType.getRootTerm();
String classifierKey = TermConverter.buildClassifierKeyFromTermCode(getRootTerm.getCode());
TermConverter termBuilder = new TermConverter(classifierKey);
attributeTermType.setRootTerm(termBuilder.build());
}
return mdAttribute;
}
return null;
}
Aggregations