use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class GeoRegistryUtil method exportListTypeShapefile.
@Transaction
public static InputStream exportListTypeShapefile(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 {
ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(version, mdBusiness, mdAttributes, criteria);
return exporter.export();
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class ListType method delete.
@Override
@Transaction
public void delete() {
// Validate there are no public versions
ListTypeVersionQuery query = new ListTypeVersionQuery(new QueryFactory());
query.WHERE(query.getListType().EQ(this));
query.AND(query.getWorking().EQ(false));
query.AND(OR.get(query.getListVisibility().EQ(ListType.PUBLIC), query.getGeospatialVisibility().EQ(ListType.PUBLIC)));
long count = query.getCount();
if (count > 0) {
throw new CannotDeletePublicListTypeException();
}
// Delete all jobs
this.getJobs().forEach(job -> {
job.delete();
});
this.getEntries().forEach(entry -> {
entry.delete();
});
super.delete();
final File directory = this.getShapefileDirectory();
if (directory.exists()) {
try {
FileUtils.deleteDirectory(directory);
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class ListTypeVersion method generateShapefile.
// public List<ExecutableJob> getJobs()
// {
// LinkedList<ExecutableJob> jobs = new LinkedList<ExecutableJob>();
//
// PublishShapefileJobQuery psjq = new PublishShapefileJobQuery(new
// QueryFactory());
// psjq.WHERE(psjq.getVersion().EQ(this));
//
// try (OIterator<? extends PublishShapefileJob> it = psjq.getIterator())
// {
// jobs.addAll(it.getAll());
// }
//
// PublishListTypeVersionJobQuery pmlvj = new
// PublishListTypeVersionJobQuery(new QueryFactory());
// pmlvj.WHERE(pmlvj.getListTypeVersion().EQ(this));
//
// try (OIterator<? extends PublishListTypeVersionJob> it =
// pmlvj.getIterator())
// {
// jobs.addAll(it.getAll());
// }
//
// return jobs;
// }
public File generateShapefile() {
String filename = this.getOid() + ".zip";
final ListType list = this.getListType();
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 {
ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(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.ProgrammingErrorException in project geoprism-registry by terraframe.
the class ListTypeVersion method buildQueryConditionsFromFilter.
private Map<MdAttributeConcreteDAOIF, Condition> buildQueryConditionsFromFilter(String filterJson, String ignoreAttribute, ComponentQuery query, MdBusinessDAOIF mdBusiness) {
Map<MdAttributeConcreteDAOIF, Condition> conditionMap = new HashMap<MdAttributeConcreteDAOIF, Condition>();
if (filterJson != null && filterJson.length() > 0) {
DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
for (int i = 0; i < filters.size(); i++) {
JsonObject filter = filters.get(i).getAsJsonObject();
String attribute = filter.get("attribute").getAsString();
if (ignoreAttribute == null || !attribute.equals(ignoreAttribute)) {
MdAttributeConcreteDAOIF mdAttr = mdBusiness.definesAttribute(attribute);
BasicCondition condition = null;
if (mdAttr instanceof MdAttributeMomentDAOIF) {
JsonObject jObject = filter.get("value").getAsJsonObject();
try {
if (jObject.has("start") && !jObject.get("start").isJsonNull()) {
String date = jObject.get("start").getAsString();
if (date.length() > 0) {
condition = query.aDateTime(attribute).GE(filterFormat.parse(date));
}
}
if (jObject.has("end") && !jObject.get("end").isJsonNull()) {
String date = jObject.get("end").getAsString();
if (date.length() > 0) {
condition = query.aDateTime(attribute).LE(filterFormat.parse(date));
}
}
} catch (ParseException e) {
throw new ProgrammingErrorException(e);
}
} else if (mdAttr instanceof MdAttributeBooleanDAOIF) {
String value = filter.get("value").getAsString();
Boolean bVal = Boolean.valueOf(value);
condition = ((AttributeBoolean) query.get(attribute)).EQ(bVal);
} else {
String value = filter.get("value").getAsString();
condition = query.get(attribute).EQ(value);
}
if (condition != null) {
if (conditionMap.containsKey(mdAttr)) {
conditionMap.put(mdAttr, conditionMap.get(mdAttr).OR(condition));
} else {
conditionMap.put(mdAttr, condition);
}
}
}
}
}
return conditionMap;
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class ListTypeVersion method bbox.
public JsonArray bbox(String uid) {
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
String tableName = mdBusiness.getTableName();
// collect all the views and extend the bounding box
ValueQuery union = new ValueQuery(new QueryFactory());
union.SELECT(union.aSQLClob(GeoserverFacade.GEOM_COLUMN, GeoserverFacade.GEOM_COLUMN, GeoserverFacade.GEOM_COLUMN));
union.FROM(tableName, tableName);
if (uid != null && uid.length() > 0) {
MdAttributeConcreteDAOIF attribute = mdBusiness.definesAttribute(DefaultAttribute.UID.getName());
String columName = attribute.getColumnName();
union.WHERE(union.aSQLCharacter(columName, columName).EQ(uid));
}
ValueQuery collected = new ValueQuery(union.getQueryFactory());
collected.SELECT(collected.aSQLAggregateClob("collected", "st_collect(" + GeoserverFacade.GEOM_COLUMN + ")", "collected"));
collected.FROM("(" + union.getSQL() + ")", "unioned");
ValueQuery outer = new ValueQuery(union.getQueryFactory());
outer.SELECT(union.aSQLAggregateDouble("minx", "st_xmin(collected)"), union.aSQLAggregateDouble("miny", "st_ymin(collected)"), union.aSQLAggregateDouble("maxx", "st_xmax(collected)"), union.aSQLAggregateDouble("maxy", "st_ymax(collected)"));
outer.FROM("(" + collected.getSQL() + ")", "collected");
try (OIterator<? extends ValueObject> iter = outer.getIterator()) {
ValueObject o = iter.next();
try {
JsonArray bboxArr = new JsonArray();
bboxArr.add(Double.parseDouble(o.getValue("minx")));
bboxArr.add(Double.parseDouble(o.getValue("miny")));
bboxArr.add(Double.parseDouble(o.getValue("maxx")));
bboxArr.add(Double.parseDouble(o.getValue("maxy")));
return bboxArr;
} catch (JSONException ex) {
throw new ProgrammingErrorException(ex);
}
} catch (Exception e) {
return null;
// throw new NoLayerDataException();
}
}
Aggregations