static final synchronized MyRelation assertRelation(CallingContext cc) throws ODKDatastoreException { MyRelation relationPrototype; Datastore ds = cc.getDatastore(); User user = cc.getUserService().getDaemonAccountUser(); relationPrototype = new MyRelation(ds.getDefaultSchemaName()); ds.assertRelation(relationPrototype, user); // may throw exception... // at this point, the prototype has become fully populated return relationPrototype; // set static variable only upon success... }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { CallingContext cc = ContextFactory.getCallingContext(this, req); User user = cc.getCurrentUser(); UserService userService = cc.getUserService(); // Check to make sure we are using the canonical server name. // If not, redirect to that name. This ensures that authentication // cookies will have the proper realm(s) established for them. String newUrl = cc.getServerURL() + BasicConsts.FORWARDSLASH + ADDR; String query = req.getQueryString(); if (query != null && query.length() != 0) { newUrl += "?" + query; } URL url = new URL(newUrl); if (!url.getHost().equalsIgnoreCase(req.getServerName())) { // we should redirect over to the proper fully-formed URL. logger.info( "Incoming servername: " + req.getServerName() + " expected: " + url.getHost() + " -- redirecting."); resp.sendRedirect(newUrl); return; } // OK. We are using the canonical server name. boolean isSuperUser = false; try { isSuperUser = userService.isSuperUser(cc); } catch (ODKDatastoreException e) { e.printStackTrace(); } // determine if this is the first time the system has not been accessed... if (isSuperUser) { // this is the super-user -- examine the isEnabled // field to determine whether this is the first time // visiting the site. If it is, force a redirect to // the site-configuration tab. boolean directToConfigTab = false; Datastore ds = cc.getDatastore(); try { long changeTimestamp = SecurityRevisionsTable.getLastSuperUserIdRevisionDate(ds, user); long reviewStamp = SecurityRevisionsTable.getLastPermissionsViewRevisionDate(ds, user); if (reviewStamp < changeTimestamp) { SecurityRevisionsTable.setLastPermissionsViewRevisionDate(ds, user); directToConfigTab = true; } } catch (ODKDatastoreException e) { e.printStackTrace(); } if (directToConfigTab) { newUrl += "#admin/permission///"; logger.info("Redirect to configuration tab: " + newUrl); resp.sendRedirect(newUrl); return; } } resp.setContentType(HtmlConsts.RESP_TYPE_HTML); resp.setCharacterEncoding(HtmlConsts.UTF8_ENCODE); PrintWriter out = resp.getWriter(); out.print(PAGE_CONTENTS_FIRST); String simpleApiKey; try { simpleApiKey = ServerPreferencesProperties.getGoogleSimpleApiKey(cc); if (simpleApiKey != null && simpleApiKey.length() != 0) { out.print("key=" + encodeParameter(simpleApiKey) + "&"); } } catch (ODKEntityNotFoundException e) { e.printStackTrace(); logger.info("Unable to access Map APIKey"); } catch (ODKOverQuotaException e) { e.printStackTrace(); logger.info("Unable to access Map APIKey"); } out.print(PAGE_CONTENTS_SECOND); }