use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class MasterListVersion method data.
public JsonObject data(Integer pageNumber, Integer pageSize, String filterJson, String sort, Boolean includeGeometries) {
if (includeGeometries == null) {
includeGeometries = Boolean.FALSE;
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
NumberFormat numberFormat = NumberFormat.getInstance(Session.getCurrentLocale());
JsonArray results = new JsonArray();
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributes();
BusinessQuery query = this.buildQuery(filterJson);
if (sort != null && sort.length() > 0) {
JsonObject jObject = JsonParser.parseString(sort).getAsJsonObject();
String attribute = jObject.get("attribute").getAsString();
String order = jObject.get("order").getAsString();
if (order.equalsIgnoreCase("DESC")) {
query.ORDER_BY_DESC(query.getS(attribute));
} else {
query.ORDER_BY_ASC(query.getS(attribute));
}
if (!attribute.equals(DefaultAttribute.CODE.getName())) {
query.ORDER_BY_ASC(query.aCharacter(DefaultAttribute.CODE.getName()));
}
}
try (OIterator<Business> iterator = query.getIterator(pageSize, pageNumber)) {
while (iterator.hasNext()) {
Business row = iterator.next();
JsonObject object = new JsonObject();
MdAttributeConcreteDAOIF mdGeometry = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
if (includeGeometries) {
Geometry geom = (Geometry) row.getObjectValue(mdGeometry.definesAttribute());
if (geom != null) {
GeoJSONWriter gw = new GeoJSONWriter();
org.wololo.geojson.Geometry gJSON = gw.write(geom);
JsonObject geojson = JsonParser.parseString(gJSON.toString()).getAsJsonObject();
object.add("geometry", geojson);
}
}
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));
}
}
}
}
results.add(object);
}
}
JsonObject page = new JsonObject();
page.addProperty("pageNumber", pageNumber);
page.addProperty("pageSize", pageSize);
page.addProperty("filter", filterJson);
page.addProperty("count", query.getCount());
page.add("results", results);
return page;
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class MasterListVersion method removeAttributeType.
public void removeAttributeType(TableMetadata metadata, AttributeType attributeType) {
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(metadata.getMdBusiness().getOid());
if (!(attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType || attributeType instanceof AttributeLocalType)) {
removeAttribute(mdBusiness, attributeType.getName());
} else if (attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType) {
removeAttribute(mdBusiness, attributeType.getName());
removeAttribute(mdBusiness, attributeType.getName() + DEFAULT_LOCALE);
for (Locale locale : locales) {
removeAttribute(mdBusiness, attributeType.getName() + locale.toString());
}
} else if (attributeType instanceof AttributeLocalType) {
removeAttribute(mdBusiness, attributeType.getName() + DEFAULT_LOCALE);
for (Locale locale : locales) {
removeAttribute(mdBusiness, attributeType.getName() + locale.toString());
}
}
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class MasterListVersion method generateShapefile.
public File generateShapefile() {
String filename = this.getOid() + ".zip";
final MasterList list = this.getMasterlist();
final File directory = list.getShapefileDirectory();
directory.mkdirs();
final File file = new File(directory, filename);
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> this.isValid(mdAttribute)).collect(Collectors.toList());
try {
MasterListShapefileExporter exporter = new MasterListShapefileExporter(this, mdBusiness, mdAttributes, null);
try (final InputStream istream = exporter.export()) {
try (final FileOutputStream fos = new FileOutputStream(file)) {
IOUtils.copy(istream, fos);
}
}
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
return file;
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class MasterListVersion method bbox.
public String bbox() {
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
double[] geometry = GeoserverFacade.getBBOX(mdBusiness.getTableName());
if (geometry != null) {
try {
JSONArray bboxArr = new JSONArray();
bboxArr.put(geometry[0]);
bboxArr.put(geometry[1]);
bboxArr.put(geometry[2]);
bboxArr.put(geometry[3]);
return bboxArr.toString();
} catch (JSONException ex) {
throw new ProgrammingErrorException(ex);
}
}
return null;
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class ServerGeoObjectTypeConverter method convertAttributeTypes.
public GeoObjectType convertAttributeTypes(Universal uni, GeoObjectType gt, MdBusiness mdBusiness) {
if (mdBusiness != null) {
MdBusinessDAOIF mdBusinessDAOIF = (MdBusinessDAOIF) BusinessFacade.getEntityDAO(mdBusiness);
// Standard attributes are defined by default on the GeoObjectType
AttributeTypeConverter builder = new AttributeTypeConverter();
List<? extends MdAttributeConcreteDAOIF> definedMdAttributeList = mdBusinessDAOIF.getAllDefinedMdAttributes();
for (MdAttributeConcreteDAOIF mdAttribute : definedMdAttributeList) {
if (this.convertMdAttributeToAttributeType(mdAttribute)) {
AttributeType attributeType = builder.build(mdAttribute);
if (attributeType != null) {
gt.addAttribute(attributeType);
}
}
}
}
return gt;
}
Aggregations