Search in sources :

Example 6 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class DimensionTree method onModelChanged.

private void onModelChanged() {
    if (needToReloadDimensions(model)) {
        clearIndicatorSpecificDimensions();
        dispatcher.execute(new GetSchema(), new MaskingAsyncMonitor(treePanel, I18N.CONSTANTS.loading()), new AsyncCallback<SchemaDTO>() {

            @Override
            public void onFailure(Throwable caught) {
            }

            @Override
            public void onSuccess(SchemaDTO result) {
                populateIndicatorSpecificDimensions(result);
                applyModelState(result);
            }
        });
    }
}
Also used : MaskingAsyncMonitor(org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 7 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class ExportSitesServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Set<Integer> activities = new HashSet<Integer>();
    if (req.getParameterValues("a") != null) {
        for (String activity : req.getParameterValues("a")) {
            activities.add(Integer.parseInt(activity));
        }
    }
    Filter filter = FilterUrlSerializer.fromQueryParameter(req.getParameter("filter"));
    SchemaDTO schema = dispatcher.execute(new GetSchema());
    SiteExporter export = new SiteExporter(dispatcher);
    for (UserDatabaseDTO db : schema.getDatabases()) {
        for (ActivityDTO activity : db.getActivities()) {
            if (!filter.isRestricted(DimensionType.Activity) || filter.getRestrictions(DimensionType.Activity).contains(activity.getId())) {
                export.export(activity, filter);
            }
        }
    }
    export.done();
    resp.setContentType("application/vnd.ms-excel");
    if (req.getHeader("User-Agent").indexOf("MSIE") != -1) {
        resp.addHeader("Content-Disposition", "attachment; filename=ActivityInfo.xls");
    } else {
        resp.addHeader("Content-Disposition", "attachment; filename=" + ("ActivityInfo Export " + new Date().toString() + ".xls").replace(" ", "_"));
    }
    OutputStream os = resp.getOutputStream();
    export.getBook().write(os);
}
Also used : Filter(org.activityinfo.shared.command.Filter) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) OutputStream(java.io.OutputStream) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Date(java.util.Date) HashSet(java.util.HashSet)

Example 8 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class SiteChangeServlet method sendNotifications.

@VisibleForTesting
void sendNotifications(int editorUserId, int siteId, ChangeType type) {
    User user = entityManager.get().find(User.class, editorUserId);
    /*
         * For our purposes, the user who initiated the change will be
         * considered the authenticated user for this thread
         */
    authProvider.set(user);
    SiteResult siteResult = dispatcher.execute(GetSites.byId(siteId));
    SiteDTO siteDTO = siteResult.getData().get(0);
    SchemaDTO schemaDTO = dispatcher.execute(new GetSchema());
    ActivityDTO activityDTO = schemaDTO.getActivityById(siteDTO.getActivityId());
    UserDatabaseDTO userDatabaseDTO = activityDTO.getDatabase();
    Date date = new Date();
    List<User> recipients = findRecipients(userDatabaseDTO.getId());
    for (User recipient : recipients) {
        try {
            // themselves!
            if (recipient.getId() != editorUserId) {
                LOGGER.info("sending sitechange notification email to " + recipient.getEmail());
                UpdateMessageBuilder message = new UpdateMessageBuilder();
                message.setDate(date);
                message.setEditor(user);
                message.setRecipient(recipient);
                message.setUserDatabaseDTO(userDatabaseDTO);
                message.setSiteDTO(siteDTO);
                message.setActivityDTO(activityDTO);
                message.setChangeType(type);
                mailSender.get().send(message.build());
            }
        } catch (Throwable t) {
            LOGGER.warning("failed sending notification email to " + recipient.getName() + " <" + recipient.getEmail() + ">: " + t.getMessage());
            t.printStackTrace();
        }
    }
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) SiteResult(org.activityinfo.shared.command.result.SiteResult) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) SiteDTO(org.activityinfo.shared.dto.SiteDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Date(java.util.Date) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method commandShouldBeSentToServerIfThereAreNoProxiesAndNoPendingCommands.

@Test
public void commandShouldBeSentToServerIfThereAreNoProxiesAndNoPendingCommands() {
    // define our expectations
    expectRemoteCall(new GetSchema());
    replay(service);
    // trigger a call
    dispatcher.execute(new GetSchema(), makeNullCallback());
    processPendingCommands();
    // verify that the command was dispatched to the server
    verify(service);
}
Also used : GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 10 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method commandsUnsuccessfullyExecutedThroughProxiesShouldBeSentToServer.

@Test
public void commandsUnsuccessfullyExecutedThroughProxiesShouldBeSentToServer() {
    GetSchema command = new GetSchema();
    expect(proxy.maybeExecute(eq(command))).andReturn(CacheResult.couldNotExecute());
    replay(proxy);
    expectRemoteCall(command);
    andCallbackWihSuccess(new SchemaDTO());
    replay(service);
    AsyncCallback callback = makeCallbackThatExpectsNonNullSuccess();
    proxyManager.registerProxy(GetSchema.class, proxy);
    dispatcher.execute(new GetSchema(), callback);
    processPendingCommands();
    verify(proxy, service, callback);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Aggregations

GetSchema (org.activityinfo.shared.command.GetSchema)65 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)56 Test (org.junit.Test)42 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)15 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)10 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)9 CreateResult (org.activityinfo.shared.command.result.CreateResult)8 CreateEntity (org.activityinfo.shared.command.CreateEntity)5 Filter (org.activityinfo.shared.command.Filter)5 HashMap (java.util.HashMap)4 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 Delete (org.activityinfo.shared.command.Delete)4 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)4 OnDataSet (org.activityinfo.server.database.OnDataSet)3 BatchCommand (org.activityinfo.shared.command.BatchCommand)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2