Search in sources :

Example 1 with CommandException

use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.

the class CreateEntityHandler method execute.

@Override
public CommandResult execute(CreateEntity cmd, User user) throws CommandException {
    Map<String, Object> properties = cmd.getProperties().getTransientMap();
    PropertyMap propertyMap = new PropertyMap(cmd.getProperties().getTransientMap());
    if ("UserDatabase".equals(cmd.getEntityName())) {
        UserDatabasePolicy policy = injector.getInstance(UserDatabasePolicy.class);
        return new CreateResult((Integer) policy.create(user, propertyMap));
    } else if ("Activity".equals(cmd.getEntityName())) {
        ActivityPolicy policy = injector.getInstance(ActivityPolicy.class);
        return new CreateResult((Integer) policy.create(user, propertyMap));
    } else if ("AttributeGroup".equals(cmd.getEntityName())) {
        return createAttributeGroup(cmd, properties);
    } else if ("Attribute".equals(cmd.getEntityName())) {
        return createAttribute(cmd, properties);
    } else if ("Indicator".equals(cmd.getEntityName())) {
        return createIndicator(user, cmd, properties);
    } else {
        throw new CommandException("Invalid entity class " + cmd.getEntityName());
    }
}
Also used : ActivityPolicy(org.activityinfo.server.command.handler.crud.ActivityPolicy) PropertyMap(org.activityinfo.server.command.handler.crud.PropertyMap) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabasePolicy(org.activityinfo.server.command.handler.crud.UserDatabasePolicy) IllegalAccessCommandException(org.activityinfo.shared.exception.IllegalAccessCommandException) CommandException(org.activityinfo.shared.exception.CommandException)

Example 2 with CommandException

use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.

the class RenderReportHtmlHandler method execute.

@Override
@LogException
public CommandResult execute(RenderReportHtml cmd, User user) throws CommandException {
    ReportElement model = cmd.getModel();
    LOGGER.fine("Model: " + model);
    // don't show the title: it will be rendered by the container
    model.setTitle(null);
    generator.generateElement(user, model, new Filter(), new DateRange());
    StringWriter writer = new StringWriter();
    try {
        renderer.render(model, writer);
    } catch (IOException e) {
        throw new CommandException(e);
    }
    return new HtmlResult(writer.toString());
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) StringWriter(java.io.StringWriter) Filter(org.activityinfo.shared.command.Filter) HtmlResult(org.activityinfo.shared.command.result.HtmlResult) ReportElement(org.activityinfo.shared.report.model.ReportElement) IOException(java.io.IOException) CommandException(org.activityinfo.shared.exception.CommandException) LogException(org.activityinfo.server.util.logging.LogException)

Example 3 with CommandException

use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.

the class UpdateMonthlyReportsHandler method execute.

@Override
public CommandResult execute(UpdateMonthlyReports cmd, User user) throws CommandException {
    Site site = em.find(Site.class, cmd.getSiteId());
    if (site == null) {
        throw new CommandException(cmd, "site " + cmd.getSiteId() + " not found for user " + user.getEmail());
    }
    Map<Month, ReportingPeriod> periods = Maps.newHashMap();
    Map<String, Object> siteHistoryChangeMap = createChangeMap();
    for (ReportingPeriod period : site.getReportingPeriods()) {
        periods.put(HandlerUtil.monthFromRange(period.getDate1(), period.getDate2()), period);
    }
    for (UpdateMonthlyReports.Change change : cmd.getChanges()) {
        ReportingPeriod period = periods.get(change.getMonth());
        if (period == null) {
            period = new ReportingPeriod(site);
            period.setId(keyGenerator.generateInt());
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.YEAR, change.getMonth().getYear());
            calendar.set(Calendar.MONTH, change.getMonth().getMonth() - 1);
            calendar.set(Calendar.DATE, 1);
            period.setDate1(calendar.getTime());
            calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
            period.setDate2(calendar.getTime());
            em.persist(period);
            periods.put(change.getMonth(), period);
        }
        updateIndicatorValue(em, period, change.getIndicatorId(), change.getValue(), false);
        siteHistoryChangeMap.put(IndicatorDTO.getPropertyName(change.getIndicatorId(), change.getMonth()), change.getValue());
    }
    siteHistoryProcessor.persistHistory(site, user, ChangeType.UPDATE, siteHistoryChangeMap);
    return new VoidResult();
}
Also used : Site(org.activityinfo.server.database.hibernate.entity.Site) Month(org.activityinfo.shared.command.Month) ReportingPeriod(org.activityinfo.server.database.hibernate.entity.ReportingPeriod) UpdateMonthlyReports(org.activityinfo.shared.command.UpdateMonthlyReports) VoidResult(org.activityinfo.shared.command.result.VoidResult) Calendar(java.util.Calendar) CommandException(org.activityinfo.shared.exception.CommandException)

Example 4 with CommandException

use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.

the class KmlDataServlet method doGet.

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.getWriter();
    int activityId = Integer.valueOf(req.getParameter("activityId"));
    // Get Authorization header
    String auth = req.getHeader("Authorization");
    // Do we allow that user?
    User user = authenticator.doAuthentication(auth);
    if (user == null) {
        // Not allowed, or no password provided so report unauthorized
        res.setHeader("WWW-Authenticate", "BASIC realm=\"Utilisateurs authorises\"");
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }
    res.setContentType("application/vnd.google-earth.kml+xml");
    try {
        writeDocument(user, res.getWriter(), activityId);
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (CommandException e) {
        e.printStackTrace();
    }
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) CommandException(org.activityinfo.shared.exception.CommandException) SAXException(org.xml.sax.SAXException)

Example 5 with CommandException

use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method commandExceptionsShouldBeCalledBackWithFailure.

@Test
public void commandExceptionsShouldBeCalledBackWithFailure() {
    expectRemoteCall(new GetSchema());
    // remote call succeeded,
    andCallbackWihSuccess(new CommandException());
    // command failed
    replay(service);
    AsyncCallback callback = makeCallbackThatExpectsFailure();
    dispatcher.execute(new GetSchema(), callback);
    processPendingCommands();
    verify(service, callback);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CommandException(org.activityinfo.shared.exception.CommandException) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Aggregations

CommandException (org.activityinfo.shared.exception.CommandException)15 User (org.activityinfo.server.database.hibernate.entity.User)3 LogException (org.activityinfo.server.util.logging.LogException)3 CommandResult (org.activityinfo.shared.command.result.CommandResult)3 PropertyMap (org.activityinfo.server.command.handler.crud.PropertyMap)2 Filter (org.activityinfo.shared.command.Filter)2 Bucket (org.activityinfo.shared.command.result.Bucket)2 CreateResult (org.activityinfo.shared.command.result.CreateResult)2 VoidResult (org.activityinfo.shared.command.result.VoidResult)2 IllegalAccessCommandException (org.activityinfo.shared.exception.IllegalAccessCommandException)2 DateRange (org.activityinfo.shared.report.model.DateRange)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 ActivityPolicy (org.activityinfo.server.command.handler.crud.ActivityPolicy)1 UserDatabasePolicy (org.activityinfo.server.command.handler.crud.UserDatabasePolicy)1