use of com.runwaysdk.query.ValueQuery in project geoprism-registry by terraframe.
the class UserInfo method page.
public static JSONObject page(Integer pageSize, Integer pageNumber) {
final RolePermissionService perms = ServiceFactory.getRolePermissionService();
List<Organization> organizations = Organization.getUserOrganizations();
boolean isSRA = perms.isSRA();
boolean isRMorRCorAC = (!isSRA && !perms.isRA()) && (perms.isRM() || perms.isRC() || perms.isAC());
List<ExternalSystem> externalSystemList = ExternalSystem.getExternalSystemsForOrg(1, 100);
JSONArray externalSystems = new JSONArray();
for (ExternalSystem externalSystem : externalSystemList) {
externalSystems.put(new JSONObject(externalSystem.toJSON().toString()));
}
if (organizations.size() > 0 || isSRA) {
ValueQuery vQuery = new ValueQuery(new QueryFactory());
GeoprismUserQuery uQuery = new GeoprismUserQuery(vQuery);
UserInfoQuery iQuery = new UserInfoQuery(vQuery);
vQuery.SELECT(uQuery.getOid(), uQuery.getUsername(), uQuery.getFirstName(), uQuery.getLastName(), uQuery.getPhoneNumber(), uQuery.getEmail(), uQuery.getInactive());
vQuery.SELECT(iQuery.getAltFirstName(), iQuery.getAltLastName(), iQuery.getAltPhoneNumber(), iQuery.getPosition());
vQuery.SELECT(iQuery.getExternalSystemOid());
vQuery.WHERE(new LeftJoinEq(uQuery.getOid(), iQuery.getGeoprismUser()));
if (organizations.size() > 0) {
// restrict by org code
OrganizationQuery orgQuery = new OrganizationQuery(vQuery);
OrganizationUserQuery relQuery = new OrganizationUserQuery(vQuery);
for (Organization org : organizations) {
orgQuery.OR(orgQuery.getCode().EQ(org.getCode()));
}
vQuery.WHERE(relQuery.parentOid().EQ(orgQuery.getOid()));
vQuery.WHERE(uQuery.getOid().EQ(relQuery.childOid()));
}
if (isRMorRCorAC) {
vQuery.WHERE(uQuery.getInactive().EQ(false));
}
vQuery.ORDER_BY_ASC(uQuery.getUsername());
return serializePage(pageSize, pageNumber, externalSystems, vQuery);
}
JSONObject page = new JSONObject();
page.put("resultSet", new JSONArray());
page.put("count", 0);
page.put("pageNumber", pageNumber);
page.put("pageSize", pageSize);
page.put("externalSystems", externalSystems);
return page;
}
use of com.runwaysdk.query.ValueQuery in project geoprism-registry by terraframe.
the class ChangeRequestService method findPageNumber.
// An attempt to do this without selectable sqls
// private int findPageNumber(String crOid, ChangeRequestQuery query, int pageSize)
// {
// QueryFactory qf = new QueryFactory();
// ValueQuery vq = new ValueQuery(qf);
//
// vq.FROM(query);
//
// vq.SELECT(query.getOid());
// vq.SELECT(query.getCreateDate());
//
// Selectable createDate = query.getCreateDate();
//
// vq.SELECT(vq.RANK("rn").OVER(null, new OrderBy(createDate, SortOrder.DESC)));
//
// vq.WHERE(query.getOid().EQ(crOid));
//
// ValueObject vo = vq.getIterator().getAll().get(0);
//
// long rowNum = Long.parseLong(vo.getValue("rn"));
//
// int pageNum = (int) ( (rowNum / pageSize) + 1 );
//
// return pageNum;
// }
private int findPageNumber(String crOid, ChangeRequestQuery query, int pageSize) {
QueryFactory qf = new QueryFactory();
ValueQuery innerVq = new ValueQuery(qf);
String sub1Sql = query.getSQL();
innerVq.FROM("(" + sub1Sql + ")", "sub1");
String createDateAlias = query.getCreateDate().getColumnAlias();
Matcher m = Pattern.compile("change_request_\\d+\\.create_date AS (create_date_\\d+),").matcher(sub1Sql);
if (m.find()) {
createDateAlias = m.group(1);
}
innerVq.SELECT(innerVq.aSQLCharacter("oid", "oid"));
// The rank function is forcing a group by, which we don't want to do. It also doesn't use our alias.
// SelectableSQLDate createDate = innerVq.aSQLDate(query.getCreateDate().getColumnAlias(), query.getCreateDate().getColumnAlias());
// AggregateFunction rank = innerVq.RANK("rn").OVER(null, new OrderBy(createDate, SortOrder.DESC));
Selectable rank = innerVq.aSQLInteger("rn", "(ROW_NUMBER() OVER (ORDER BY " + createDateAlias + " DESC))");
innerVq.SELECT(rank);
ValueQuery outerVq = new ValueQuery(qf);
outerVq.FROM("(" + innerVq.getSQL() + ")", "sub2");
Selectable oidSel = outerVq.aSQLCharacter("oid", "oid");
outerVq.SELECT(oidSel);
outerVq.SELECT(outerVq.aSQLInteger("rn", "rn"));
outerVq.WHERE(oidSel.EQ(crOid));
List<ValueObject> voList = outerVq.getIterator().getAll();
if (voList.size() > 0) {
ValueObject vo = voList.get(0);
long rowNum = Long.parseLong(vo.getValue("rn"));
int pageNum = (int) ((rowNum / pageSize) + 1);
return pageNum;
} else {
return 1;
}
}
use of com.runwaysdk.query.ValueQuery in project geoprism-registry by terraframe.
the class VectorTileBuilder method writeVectorTiles.
protected byte[] writeVectorTiles(String layerName, Envelope envelope, ValueQuery query) throws IOException {
OIterator<ValueObject> iterator = query.getIterator();
try {
List<Geometry> geometries = new LinkedList<Geometry>();
while (iterator.hasNext()) {
ValueObject object = iterator.next();
AttributeGeometryIF attributeIF = (AttributeGeometryIF) object.getAttributeIF(GeoserverFacade.GEOM_COLUMN);
Geometry geometry = attributeIF.getGeometry();
geometry.setUserData(this.getUserData(object));
geometries.add(geometry);
}
GeometryFactory geomFactory = new GeometryFactory();
IGeometryFilter acceptAllGeomFilter = geometry -> true;
MvtLayerParams layerParams = new MvtLayerParams();
TileGeomResult tileGeom = JtsAdapter.createTileGeom(geometries, envelope, geomFactory, layerParams, acceptAllGeomFilter);
final VectorTile.Tile.Builder tileBuilder = VectorTile.Tile.newBuilder();
// Create MVT layer
final MvtLayerProps layerProps = new MvtLayerProps();
final IUserDataConverter ignoreUserData = new UserDataConverter();
// MVT tile geometry to MVT features
final List<VectorTile.Tile.Feature> features = JtsAdapter.toFeatures(tileGeom.mvtGeoms, layerProps, ignoreUserData);
final VectorTile.Tile.Layer.Builder layerBuilder = MvtLayerBuild.newLayerBuilder(layerName, layerParams);
layerBuilder.addAllFeatures(features);
MvtLayerBuild.writeProps(layerBuilder, layerProps);
// Build MVT layer
final VectorTile.Tile.Layer layer = layerBuilder.build();
// Add built layer to MVT
tileBuilder.addLayers(layer);
// / Build MVT
Tile mvt = tileBuilder.build();
return mvt.toByteArray();
} finally {
iterator.close();
}
}
Aggregations