Search in sources :

Example 1 with UnexpectedCommandException

use of org.activityinfo.legacy.shared.exception.UnexpectedCommandException in project activityinfo by bedatadriven.

the class TimeoutDispatcherMock method execute.

@Override
public <T extends CommandResult> void execute(Command<T> command, AsyncCallback<T> callback) {
    executeCounter.incrementAndGet();
    callback.onFailure(new UnexpectedCommandException());
}
Also used : UnexpectedCommandException(org.activityinfo.legacy.shared.exception.UnexpectedCommandException)

Example 2 with UnexpectedCommandException

use of org.activityinfo.legacy.shared.exception.UnexpectedCommandException in project activityinfo by bedatadriven.

the class UpdateReportModelHandler method execute.

@Override
public CommandResult execute(final UpdateReportModel cmd, final User user) throws CommandException {
    Query query = em.createQuery("select r from ReportDefinition r where r.id in (:id)").setParameter("id", cmd.getModel().getId());
    ReportDefinition result = (ReportDefinition) query.getSingleResult();
    if (result.getOwner().getId() != user.getId()) {
        throw new IllegalAccessCommandException("Current user does not have the right to edit this report");
    }
    // Invalidate the cache BEFORE attempting to update the database,
    // otherwise, we will leave the system in an inconsistent state if
    // the database update succeeds, but the memcache delete fails.
    invalidateMemcache(cmd.getModel().getId());
    // Now that we're sure that the memcache is clear of the old copy,
    // we can safely update the underlying persistant datastore
    result.setTitle(cmd.getModel().getTitle());
    try {
        result.setXml(ReportParserJaxb.createXML(cmd.getModel()));
    } catch (JAXBException e) {
        throw new UnexpectedCommandException(e);
    }
    em.persist(result);
    return null;
}
Also used : Query(javax.persistence.Query) IllegalAccessCommandException(org.activityinfo.legacy.shared.exception.IllegalAccessCommandException) UnexpectedCommandException(org.activityinfo.legacy.shared.exception.UnexpectedCommandException) JAXBException(javax.xml.bind.JAXBException) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Aggregations

UnexpectedCommandException (org.activityinfo.legacy.shared.exception.UnexpectedCommandException)2 Query (javax.persistence.Query)1 JAXBException (javax.xml.bind.JAXBException)1 IllegalAccessCommandException (org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)1 ReportDefinition (org.activityinfo.server.database.hibernate.entity.ReportDefinition)1