Search in sources :

Example 1 with RemoveResult

use of org.activityinfo.legacy.shared.command.result.RemoveResult in project activityinfo by bedatadriven.

the class RemovePartnerHandler method execute.

@Override
public CommandResult execute(RemovePartner cmd, User user) {
    // verify the current user has access to this site
    Database db = em.getReference(Database.class, cmd.getDatabaseId());
    PermissionOracle.using(em).isManagePartnersAllowed(db, user);
    // check to see if there are already sites associated with this partner
    int siteCount = ((Number) em.createQuery("select count(s) " + "from Site s " + "where s.activity.id in (select a.id from Activity a where a" + ".database.id = :dbId " + "AND a.dateDeleted is null" + ") " + "and s.partner.id = :partnerId " + "and s.dateDeleted is null").setParameter("dbId", cmd.getDatabaseId()).setParameter("partnerId", cmd.getPartnerId()).getSingleResult()).intValue();
    if (siteCount > 0) {
        return new RemoveFailedResult();
    }
    db.getPartners().remove(em.getReference(Partner.class, cmd.getPartnerId()));
    db.setLastSchemaUpdate(new Date());
    return new RemoveResult();
}
Also used : RemoveResult(org.activityinfo.legacy.shared.command.result.RemoveResult) RemoveFailedResult(org.activityinfo.legacy.shared.command.result.RemoveFailedResult) Database(org.activityinfo.server.database.hibernate.entity.Database) Partner(org.activityinfo.server.database.hibernate.entity.Partner) RemovePartner(org.activityinfo.legacy.shared.command.RemovePartner) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 RemovePartner (org.activityinfo.legacy.shared.command.RemovePartner)1 RemoveFailedResult (org.activityinfo.legacy.shared.command.result.RemoveFailedResult)1 RemoveResult (org.activityinfo.legacy.shared.command.result.RemoveResult)1 Database (org.activityinfo.server.database.hibernate.entity.Database)1 Partner (org.activityinfo.server.database.hibernate.entity.Partner)1