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