use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class GeoRegistryUtil method exportMasterListShapefile.
@Transaction
public static InputStream exportMasterListShapefile(String oid, String filterJson) {
MasterListVersion version = MasterListVersion.get(oid);
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(version.getMdBusinessOid());
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> version.isValid(mdAttribute)).collect(Collectors.toList());
if (filterJson.contains("invalid")) {
mdAttributes = mdAttributes.stream().filter(mdAttribute -> !mdAttribute.definesAttribute().equals("invalid")).collect(Collectors.toList());
}
try {
MasterListShapefileExporter exporter = new MasterListShapefileExporter(version, mdBusiness, mdAttributes, filterJson);
return exporter.export();
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class GeoRegistryUtil method exportListTypeExcel.
@Transaction
public static InputStream exportListTypeExcel(String oid, String json) {
ListTypeVersion version = ListTypeVersion.get(oid);
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(version.getMdBusinessOid());
JsonObject criteria = (json != null) ? JsonParser.parseString(json).getAsJsonObject() : new JsonObject();
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> version.isValid(mdAttribute)).collect(Collectors.toList());
if (json.contains("invalid")) {
mdAttributes = mdAttributes.stream().filter(mdAttribute -> !mdAttribute.definesAttribute().equals("invalid")).collect(Collectors.toList());
}
try {
ListTypeExcelExporter exporter = new ListTypeExcelExporter(version, mdBusiness, mdAttributes, null, criteria);
return exporter.export();
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class ListTypeVersion method record.
public JsonObject record(String uid) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
NumberFormat numberFormat = NumberFormat.getInstance(Session.getCurrentLocale());
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributes();
BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
query.WHERE(query.get(DefaultAttribute.UID.getName()).EQ(uid));
JsonObject record = new JsonObject();
record.addProperty("recordType", "LIST");
record.addProperty("version", this.getOid());
record.add("typeLabel", LocalizedValueConverter.convert(this.getListType().getDisplayLabel()).toJSON());
record.add("attributes", this.getAttributesAsJson());
try (OIterator<Business> iterator = query.getIterator()) {
if (iterator.hasNext()) {
Business row = iterator.next();
JsonObject object = new JsonObject();
object.addProperty(ORIGINAL_OID, row.getValue(ORIGINAL_OID));
for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
if (this.isValid(mdAttribute)) {
String attributeName = mdAttribute.definesAttribute();
Object value = row.getObjectValue(attributeName);
if (value != null) {
if (value instanceof Double) {
object.addProperty(mdAttribute.definesAttribute(), numberFormat.format((Double) value));
} else if (value instanceof Number) {
object.addProperty(mdAttribute.definesAttribute(), (Number) value);
} else if (value instanceof Boolean) {
object.addProperty(mdAttribute.definesAttribute(), (Boolean) value);
} else if (value instanceof String) {
object.addProperty(mdAttribute.definesAttribute(), (String) value);
} else if (value instanceof Character) {
object.addProperty(mdAttribute.definesAttribute(), (Character) value);
} else if (value instanceof Date) {
object.addProperty(mdAttribute.definesAttribute(), format.format((Date) value));
}
}
}
}
record.add("data", object);
}
}
JsonArray bbox = this.bbox(uid);
if (bbox == null || bbox.size() == 0) {
bbox = this.bbox(null);
}
record.add("bbox", bbox);
return record;
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class MasterListVersion method getAttributesAsJson.
private JsonArray getAttributesAsJson() {
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
MasterList list = this.getMasterlist();
Map<String, JsonArray> dependencies = new HashMap<String, JsonArray>();
Map<String, String> baseAttributes = new HashMap<String, String>();
List<String> attributesOrder = new LinkedList<String>();
JsonArray hierarchies = list.getHierarchiesAsJson();
for (int i = 0; i < hierarchies.size(); i++) {
JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
List<String> pCodes = list.getParentCodes(hierarchy);
if (pCodes.size() > 0) {
String hCode = hierarchy.get(DefaultAttribute.CODE.getName()).getAsString();
String previous = null;
for (String pCode : pCodes) {
String attributeName = hCode.toLowerCase() + pCode.toLowerCase();
baseAttributes.put(attributeName, attributeName);
baseAttributes.put(attributeName + DEFAULT_LOCALE, attributeName);
for (Locale locale : locales) {
baseAttributes.put(attributeName + locale.toString(), attributeName);
}
attributesOrder.add(attributeName);
attributesOrder.add(attributeName + DEFAULT_LOCALE);
for (Locale locale : locales) {
attributesOrder.add(attributeName + locale.toString());
}
if (previous != null) {
addDependency(dependencies, attributeName, previous);
addDependency(dependencies, attributeName + DEFAULT_LOCALE, previous);
for (Locale locale : locales) {
addDependency(dependencies, attributeName + locale.toString(), previous);
}
}
previous = attributeName;
}
if (previous != null) {
addDependency(dependencies, DefaultAttribute.CODE.getName(), previous);
addDependency(dependencies, DefaultAttribute.DISPLAY_LABEL.getName() + DEFAULT_LOCALE, previous);
for (Locale locale : locales) {
addDependency(dependencies, DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString(), previous);
}
}
}
}
baseAttributes.put(DefaultAttribute.CODE.getName(), DefaultAttribute.CODE.getName());
baseAttributes.put(DefaultAttribute.DISPLAY_LABEL.getName() + DEFAULT_LOCALE, DefaultAttribute.CODE.getName());
for (Locale locale : locales) {
baseAttributes.put(DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString(), DefaultAttribute.CODE.getName());
}
attributesOrder.add(DefaultAttribute.CODE.getName());
attributesOrder.add(DefaultAttribute.DISPLAY_LABEL.getName() + DEFAULT_LOCALE);
for (Locale locale : locales) {
attributesOrder.add(DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString());
}
JsonArray attributes = new JsonArray();
String mdBusinessId = this.getMdBusinessOid();
if (mdBusinessId != null && mdBusinessId.length() > 0) {
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(mdBusinessId);
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered();
Collections.sort(mdAttributes, new ListTypeAttributeComparator(attributesOrder, mdAttributes));
MdAttributeConcreteDAOIF mdGeometry = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
if (mdGeometry instanceof MdAttributePointDAOIF) {
JsonObject longitude = new JsonObject();
longitude.addProperty(NAME, "longitude");
longitude.addProperty(LABEL, LocalizationFacade.localize(GeoObjectImportConfiguration.LONGITUDE_KEY));
longitude.addProperty(TYPE, "none");
attributes.add(longitude);
JsonObject latitude = new JsonObject();
latitude.addProperty(NAME, "latitude");
latitude.addProperty(LABEL, LocalizationFacade.localize(GeoObjectImportConfiguration.LATITUDE_KEY));
latitude.addProperty(TYPE, "none");
attributes.add(latitude);
}
for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
if (this.isValid(mdAttribute)) {
String attributeName = mdAttribute.definesAttribute();
try {
MasterListAttributeGroup group = MasterListAttributeGroup.getByKey(mdAttribute.getOid());
if (group != null) {
baseAttributes.put(mdAttribute.definesAttribute(), group.getSourceAttribute().getAttributeName());
}
} catch (DataNotFoundException e) {
// Ignore
}
JsonObject attribute = new JsonObject();
attribute.addProperty(NAME, attributeName);
attribute.addProperty(LABEL, mdAttribute.getDisplayLabel(Session.getCurrentLocale()));
attribute.addProperty(TYPE, baseAttributes.containsKey(attributeName) ? "list" : "input");
attribute.addProperty(BASE, baseAttributes.containsKey(attributeName) ? baseAttributes.get(attributeName) : attributeName);
attribute.add(DEPENDENCY, dependencies.containsKey(attributeName) ? dependencies.get(attributeName) : new JsonArray());
if (mdAttribute instanceof MdAttributeMomentDAOIF) {
attribute.addProperty(TYPE, "date");
attribute.add(VALUE, new JsonObject());
}
attributes.add(attribute);
}
}
}
return attributes;
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class MasterListVersion method values.
public JsonArray values(String value, String attributeName, String valueAttribute, String filterJson) {
DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
JsonArray results = new JsonArray();
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
ValueQuery vQuery = new ValueQuery(new QueryFactory());
BusinessQuery query = new BusinessQuery(vQuery, mdBusiness.definesType());
vQuery.SELECT_DISTINCT(query.get(attributeName, "label"), query.get(valueAttribute, "value"));
vQuery.FROM(query);
Map<MdAttributeConcreteDAOIF, Condition> conditionMap = this.buildQueryConditionsFromFilter(filterJson, attributeName, query, mdBusiness);
for (Condition condition : conditionMap.values()) {
vQuery.WHERE(condition);
}
if (value != null && value.length() > 0) {
vQuery.WHERE(query.aCharacter(attributeName).LIKEi("%" + value + "%"));
}
vQuery.ORDER_BY_ASC(query.get(attributeName));
OIterator<ValueObject> it = vQuery.getIterator(100, 1);
try {
while (it.hasNext()) {
ValueObject vObject = it.next();
JsonObject result = new JsonObject();
result.addProperty("label", vObject.getValue("label"));
result.addProperty("value", vObject.getValue("value"));
results.add(result);
}
} finally {
it.close();
}
return results;
}
Aggregations