Search in sources :

Example 26 with SqlQuery

use of com.bedatadriven.rebar.sql.client.query.SqlQuery in project activityinfo by bedatadriven.

the class LocationUpdateBuilder method linkAdminEntities.

private void linkAdminEntities() throws JSONException {
    SqlQuery query = SqlQuery.select().appendColumn("K.AdminEntityId").appendColumn("K.LocationId").from(Tables.LOCATION, "L").innerJoin(Tables.LOCATION_ADMIN_LINK, "K").on("L.LocationId=K.LocationId").where("L.locationTypeId").equalTo(locationType.getId()).where("L.version").greaterThan(localVersion);
    batch.insert().into(Tables.LOCATION_ADMIN_LINK).from(query).execute(em);
}
Also used : SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery)

Example 27 with SqlQuery

use of com.bedatadriven.rebar.sql.client.query.SqlQuery in project activityinfo by bedatadriven.

the class LocationUpdateBuilder method queryChanged.

private void queryChanged() {
    SqlQuery query = SqlQuery.select().appendColumn("LocationId").appendColumn("Name").appendColumn("Axe").appendColumn("X").appendColumn("Y").appendColumn("LocationTypeId").appendColumn("workflowStatusId").from(Tables.LOCATION).where("locationTypeId").equalTo(locationType.getId()).where("version").greaterThan(localVersion);
    batch.insert().into(Tables.LOCATION).from(query).execute(em);
}
Also used : SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery)

Example 28 with SqlQuery

use of com.bedatadriven.rebar.sql.client.query.SqlQuery in project activityinfo by bedatadriven.

the class GetReportModelHandler method loadMetadataAndCallback.

private void loadMetadataAndCallback(final GetReportModel cmd, final ExecutionContext context, final ReportDTO reportDTO, final AsyncCallback<ReportDTO> callback) {
    final int userId = context.getUser().getId();
    SqlQuery mySubscriptions = SqlQuery.selectAll().from("reportsubscription").where("userId").equalTo(userId);
    SqlQuery myDatabases = SqlQuery.selectSingle("d.databaseid").from("userdatabase", "d").leftJoin(SqlQuery.selectAll().from(Tables.USER_PERMISSION, "UserPermission").where("UserPermission.UserId").equalTo(userId), "p").on("p.DatabaseId = d.DatabaseId").where("d.ownerUserId").equalTo(userId).or("p.AllowView").equalTo(1);
    SqlQuery.select().appendColumn("r.reportTemplateId", "reportId").appendColumn("r.title", "title").appendColumn("r.ownerUserId", "ownerUserId").appendColumn("o.name", "ownerName").appendColumn("s.dashboard", "dashboard").appendColumn("s.emaildelivery", "emaildelivery").appendColumn("s.emailday", "emailday").appendColumn(SqlQuery.selectSingle("max(defaultDashboard)").from("reportvisibility", "v").where("v.databaseId").in(myDatabases).whereTrue("v.reportid = r.reportTemplateId"), "defaultDashboard").from("reporttemplate", "r").leftJoin("userlogin o").on("o.userid = r.ownerUserId").leftJoin(mySubscriptions, "s").on("r.reportTemplateId = s.reportId").where("r.ownerUserId").equalTo(userId).where("r.reportTemplateId").equalTo(cmd.getReportId()).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(final SqlTransaction tx, final SqlResultSet results) {
            List<ReportMetadataDTO> dtos = Lists.newArrayList();
            for (SqlResultSetRow row : results.getRows()) {
                ReportMetadataDTO dto = new ReportMetadataDTO();
                dto.setId(row.getInt("reportId"));
                dto.setAmOwner(row.getInt("ownerUserId") == userId);
                dto.setOwnerName(row.getString("ownerName"));
                dto.setTitle(row.getString("title"));
                dto.setEditAllowed(dto.getAmOwner());
                if (!row.isNull("emaildelivery")) {
                    dto.setEmailDelivery(EmailDelivery.valueOf(row.getString("emaildelivery")));
                }
                if (row.isNull("emailday")) {
                    dto.setDay(1);
                } else {
                    dto.setDay(row.getInt("emailday"));
                }
                if (row.isNull("dashboard")) {
                    // inherited from database-wide visibility
                    dto.setDashboard(!row.isNull("defaultDashboard") && row.getBoolean("defaultDashboard"));
                } else {
                    dto.setDashboard(row.getBoolean("dashboard"));
                }
                dtos.add(dto);
            }
            if (dtos.size() == 0) {
                ReportMetadataDTO dummy = new ReportMetadataDTO();
                dummy.setId(cmd.getReportId());
                dtos.add(dummy);
            }
            // there should be only one result
            reportDTO.setReportMetadataDTO(dtos.get(0));
            // exit handler with both the report and metadata objects
            // filled
            memcache(cmd, reportDTO);
            callback.onSuccess(reportDTO);
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) List(java.util.List) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) ReportMetadataDTO(org.activityinfo.legacy.shared.model.ReportMetadataDTO)

Aggregations

SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)28 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)14 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)13 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)13 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)11 Promise (org.activityinfo.promise.Promise)4 List (java.util.List)3 Filter (org.activityinfo.legacy.shared.command.Filter)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Set (java.util.Set)2 DimensionType (org.activityinfo.legacy.shared.command.DimensionType)2 LocationResult (org.activityinfo.legacy.shared.command.result.LocationResult)2 AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)2 LocationDTO (org.activityinfo.legacy.shared.model.LocationDTO)2 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 HashMap (java.util.HashMap)1 GetDimensionLabels (org.activityinfo.legacy.shared.command.GetDimensionLabels)1 DimensionLabels (org.activityinfo.legacy.shared.command.GetDimensionLabels.DimensionLabels)1 AdminEntityResult (org.activityinfo.legacy.shared.command.result.AdminEntityResult)1