Search in sources :

Example 21 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class LocalGetSchemaHandlerIntTest method forDatabaseOwner.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void forDatabaseOwner() throws CommandException {
    synchronize();
    SchemaDTO schema = executeLocally(new GetSchema());
    assertThat(schema.getDatabases().size(), equalTo(3));
    assertThat(schema.getDatabaseById(1).isDesignAllowed(), equalTo(true));
    assertThat(schema.getDatabaseById(1).getAmOwner(), equalTo(true));
    assertThat(schema.getDatabaseById(2).getAmOwner(), equalTo(true));
    assertThat(schema.getDatabaseById(1).getOwnerName(), equalTo("Alex"));
}
Also used : SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 22 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO 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 23 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO 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 24 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO 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 25 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class PartnerTest method testAddNewPartner.

@Test
public void testAddNewPartner() throws Exception {
    PartnerDTO newPartner = new PartnerDTO();
    newPartner.setName("VDE");
    newPartner.setFullName("Vision d'Espoir");
    CreateResult cr = execute(new UpdatePartner(1, newPartner));
    SchemaDTO schema = execute(new GetSchema());
    PartnerDTO partner = schema.getDatabaseById(1).getPartnerById(cr.getNewId());
    Assert.assertNotNull(partner);
    Assert.assertEquals("VDE", partner.getName());
    Assert.assertEquals("Vision d'Espoir", partner.getFullName());
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Test(org.junit.Test)

Aggregations

SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)29 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)22 Test (org.junit.Test)19 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)9 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)7 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)4 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)4 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)3 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)3 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)3 Function (com.google.common.base.Function)2 Delete (org.activityinfo.legacy.shared.command.Delete)2 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)2 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)2 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)2 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)2 User (org.activityinfo.server.database.hibernate.entity.User)2 CacheResult (org.activityinfo.ui.client.dispatch.remote.cache.CacheResult)2 Before (org.junit.Before)2