Search in sources :

Example 6 with SiteHistory

use of org.activityinfo.server.database.hibernate.entity.SiteHistory in project activityinfo by bedatadriven.

the class ActivityDigestModelBuilder method findLastEdit.

@VisibleForTesting
@SuppressWarnings("unchecked")
SiteHistory findLastEdit(Database database) {
    Query query = entityManager.get().createQuery("select h from SiteHistory h " + "where h.site.activity.database = :database " + "order by h.timeCreated desc");
    query.setParameter("database", database);
    query.setMaxResults(1);
    List<SiteHistory> list = query.getResultList();
    return (list != null && list.size() == 1) ? list.get(0) : null;
}
Also used : Query(javax.persistence.Query) SiteHistory(org.activityinfo.server.database.hibernate.entity.SiteHistory) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with SiteHistory

use of org.activityinfo.server.database.hibernate.entity.SiteHistory in project activityinfo by bedatadriven.

the class GeoDigestRenderer method renderSites.

private void renderSites(StringBuilder html, DatabaseModel databaseModel, Collection<Integer> siteIds) {
    if (!siteIds.isEmpty()) {
        for (Integer siteId : siteIds) {
            SiteResult siteResult = dispatcher.execute(GetSites.byId(siteId));
            SiteDTO siteDTO = siteResult.getData().get(0);
            ActivityDTO activityDTO = databaseModel.getModel().getSchemaDTO().getActivityById(siteDTO.getActivityId());
            // Check to see if this activity is visible to the user...
            if (activityDTO != null) {
                List<SiteHistory> histories = findSiteHistory(siteId, databaseModel.getModel().getUserDigest().getFrom());
                for (SiteHistory history : histories) {
                    html.append("<span class='geo-site' style='margin-left:10px;'>&bull; ");
                    html.append(I18N.MESSAGES.geoDigestSiteMsg(history.getUser().getEmail(), history.getUser().getName(), activityDTO.getName(), siteDTO.getLocationName()));
                    Date targetDate = databaseModel.getModel().getUserDigest().getDate();
                    Date creationDate = new Date(history.getTimeCreated());
                    if (DateCalc.isOnToday(targetDate, creationDate)) {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateToday(creationDate));
                    } else if (DateCalc.isOnYesterday(targetDate, creationDate)) {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateYesterday(creationDate));
                    } else {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateOther(creationDate));
                    }
                    html.append("</span><br>");
                }
            }
        }
    }
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SiteHistory(org.activityinfo.server.database.hibernate.entity.SiteHistory) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Aggregations

SiteHistory (org.activityinfo.server.database.hibernate.entity.SiteHistory)7 Query (javax.persistence.Query)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Date (java.util.Date)2 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 User (org.activityinfo.server.database.hibernate.entity.User)2 EntityManager (javax.persistence.EntityManager)1 SiteCommand (org.activityinfo.legacy.shared.command.SiteCommand)1 CommandException (org.activityinfo.legacy.shared.exception.CommandException)1 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)1 Partner (org.activityinfo.server.database.hibernate.entity.Partner)1 Site (org.activityinfo.server.database.hibernate.entity.Site)1 ActivityMap (org.activityinfo.server.digest.activity.ActivityDigestModel.ActivityMap)1 DatabaseModel (org.activityinfo.server.digest.activity.ActivityDigestModel.DatabaseModel)1 PartnerActivityModel (org.activityinfo.server.digest.activity.ActivityDigestModel.PartnerActivityModel)1 Timed (org.activityinfo.server.util.monitoring.Timed)1 JSONObject (org.json.JSONObject)1