Search in sources :

Example 36 with GetSchema

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

the class ConfigLoader method load.

@Override
public void load(final PageId pageId, final PageState place, final AsyncCallback<Page> callback) {
    GWT.runAsync(new RunAsyncCallback() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess() {
            final Page page = pageProviders.get(pageId).get();
            if (page == null) {
                callback.onFailure(new Exception("ConfigLoader didn't know how to handle " + place.toString()));
            } else if (page instanceof DbPage) {
                dispatch.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        callback.onFailure(caught);
                    }

                    @Override
                    public void onSuccess(SchemaDTO result) {
                        DbPageState dbPlace = (DbPageState) place;
                        ((DbPage) page).go(result.getDatabaseById(dbPlace.getDatabaseId()));
                        callback.onSuccess(page);
                    }
                });
            } else {
                page.navigate(place);
                callback.onSuccess(page);
            }
        }
    });
}
Also used : RunAsyncCallback(com.google.gwt.core.client.RunAsyncCallback) IndicatorLinkPage(org.activityinfo.ui.client.page.config.link.IndicatorLinkPage) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO)

Example 37 with GetSchema

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

the class LocationTypeProxy method load.

@Override
public void load(DataReader<ListLoadResult<LocationTypeEntry>> reader, Object loadConfig, AsyncCallback<ListLoadResult<LocationTypeEntry>> callback) {
    dispatcher.execute(new GetSchema()).then(new Function<SchemaDTO, ListLoadResult<LocationTypeEntry>>() {

        @Override
        public ListLoadResult<LocationTypeEntry> apply(SchemaDTO schema) {
            // Build a dictionary of databases that have been shared with the user
            Map<Integer, String> databaseNames = new HashMap<>();
            for (UserDatabaseDTO db : schema.getDatabases()) {
                databaseNames.put(db.getId(), db.getName());
            }
            List<LocationTypeEntry> list = new ArrayList<>();
            for (LocationTypeDTO locationType : schema.getCountryById(countryId).getLocationTypes()) {
                if (!locationType.isDeleted()) {
                    if (locationType.getDatabaseId() == null) {
                        list.add(new LocationTypeEntry(locationType));
                    } else {
                        list.add(new LocationTypeEntry(locationType, databaseNames.get(locationType.getDatabaseId())));
                    }
                }
            }
            Collections.sort(list);
            return new BaseListLoadResult<>(list);
        }
    }).then(callback);
}
Also used : UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) LocationTypeDTO(org.activityinfo.legacy.shared.model.LocationTypeDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) Function(com.google.common.base.Function) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Example 38 with GetSchema

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

the class GeoDigestModelBuilder method createModel.

@Override
public GeoDigestModel createModel(UserDigest userDigest) throws IOException {
    GeoDigestModel model = new GeoDigestModel(userDigest);
    List<Database> databases = findDatabases(userDigest.getUser());
    LOGGER.finest("found " + databases.size() + " database(s) for user " + userDigest.getUser().getId());
    if (!databases.isEmpty()) {
        model.setSchemaDTO(dispatcher.execute(new GetSchema()));
        for (Database database : databases) {
            createDatabaseModel(model, database);
        }
    }
    return model;
}
Also used : Database(org.activityinfo.server.database.hibernate.entity.Database) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Example 39 with GetSchema

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

the class KmlActivityServlet method doGet.

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    // 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=\"ActivityInfo\"");
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }
    String baseURL = (req.isSecure() ? "https" : "http") + "://" + req.getServerName() + ":" + req.getServerPort() + "/earth/sites?activityId=";
    SchemaDTO schemaDTO = dispatcher.execute(new GetSchema());
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("schema", schemaDTO);
    map.put("baseURL", baseURL);
    Template tpl = templateCfg.getTemplate("kml/ActivitiesNetworkLink.kml.ftl");
    res.setContentType("application/vnd.google-earth.kml+xml; filename=ActivityInfo.kml");
    res.setCharacterEncoding("UTF-8");
    try {
        tpl.process(map, res.getWriter());
    } catch (TemplateException e) {
        LOGGER.log(Level.SEVERE, "Exception rendering KML", e);
        res.setStatus(500);
    }
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Template(freemarker.template.Template)

Example 40 with GetSchema

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

the class UpdatePartnerHandlerTest method newWithSameName.

@Test
public void newWithSameName() {
    PartnerDTO newNRC = new PartnerDTO();
    newNRC.setName("NRC");
    newNRC.setFullName("National Red Cross");
    execute(new UpdatePartner(HEALTH_DATABASE, newNRC));
    SchemaDTO schema = execute(new GetSchema());
    PartnerDTO nrc1 = schema.getDatabaseById(NFI_DATABASE).getPartners().stream().filter(p -> p.getName().equals("NRC")).findAny().get();
    PartnerDTO nrc2 = schema.getDatabaseById(HEALTH_DATABASE).getPartners().stream().filter(p -> p.getName().equals("NRC")).findAny().get();
    assertThat(nrc1.getId(), not(equalTo(nrc2.getId())));
    assertThat(nrc1.getFullName(), nullValue());
    assertThat(nrc2.getFullName(), equalTo("National Red Cross"));
}
Also used : GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Test(org.junit.Test)

Aggregations

GetSchema (org.activityinfo.legacy.shared.command.GetSchema)42 Test (org.junit.Test)27 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)22 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)11 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)9 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)7 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)6 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)4 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)4 CloneDatabase (org.activityinfo.legacy.shared.command.CloneDatabase)3 OnDataSet (org.activityinfo.server.database.OnDataSet)3 Delete (org.activityinfo.legacy.shared.command.Delete)2 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)2 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)2 CacheResult (org.activityinfo.ui.client.dispatch.remote.cache.CacheResult)2 NullCallback (com.bedatadriven.rebar.async.NullCallback)1 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)1