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"));
}
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);
}
}
});
}
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);
}
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);
}
}
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());
}
Aggregations