List of usage examples for java.lang Long Long
@Deprecated(since = "9") public Long(String s) throws NumberFormatException
From source file:edu.lafayette.metadb.web.authentication.Login.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) *//*from w w w . j a v a 2s. com*/ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub PrintWriter out = response.getWriter(); String username = request.getParameter("username-login"); String pwd = request.getParameter("password-login"); JSONObject output = new JSONObject(); try { User user = UserManDAO.getUserData(username); //SysLogDAO.log(username, Global.SYSLOG_AUTH, "User "+username+" trying to login."); //User != null means DB conn succeeded if (user != null && !user.getUserName().equals("")) { MetaDbHelper.note("User is not null."); if (UserManDAO.checkPassword(username, pwd)) { SysLogDAO.log(username, Global.SYSLOG_AUTH, "User " + username + ": successfully logged in."); long last_login = new Long(user.getLast_login()); HttpSession session = request.getSession(); String project = ProjectsDAO.getProjectList().isEmpty() ? "" : ProjectsDAO.getProjectList().get(0); setUpSession(session, username, project); String last_date = ""; if (!UserManDAO.updateLoginTime(username, session.getLastAccessedTime())) last_date = "error"; else if (last_login != 0) { Date date = new Date(last_login + 5 * 3600 * 1000); last_date = date.toString(); } session.setAttribute(Global.SESSION_LOGIN_TIME, last_login); output.put("username", username); output.put("admin", user.getType().equals(Global.USER_ADMIN)); output.put("local", user.getAuthType().equals("Local")); output.put("last_login", last_date); output.put("success", true); output.put("parser_running", MetaDbHelper.getParserStatus()); output.put("record_count", MetaDbHelper.getItemCount()); output.put("log_types", Global.eventTypes); String[] last_page = UserManDAO.getLastProj(username).split(";"); if (last_page.length > 1) { output.put("last_proj", last_page[0]); output.put("last_item", last_page[1]); } } else { SysLogDAO.log(username, Global.SYSLOG_AUTH, "User " + username + ": Authentication error, could not log in."); output.put("success", false); output.put("message", "Username/Password mismatch"); } } else if (user != null && user.getUserName().equals("")) { SysLogDAO.log(Global.UNKNOWN_USER, Global.SYSLOG_AUTH, "UNKNOWN user: " + username); output.put("success", false); output.put("message", "Username/Password mismatch"); } else { output.put("success", false); output.put("message", "Connection to database cannot be established"); } out.print(output); } catch (Exception e) { MetaDbHelper.logEvent(e); } out.flush(); }
From source file:FileTableDemo.java
public Object getValueAt(int row, int col) { File f = new File(dir, filenames[row]); switch (col) { case 0://from w w w . j a va 2 s .co m return filenames[row]; case 1: return new Long(f.length()); case 2: return new Date(f.lastModified()); case 3: return f.isDirectory() ? Boolean.TRUE : Boolean.FALSE; case 4: return f.canRead() ? Boolean.TRUE : Boolean.FALSE; case 5: return f.canWrite() ? Boolean.TRUE : Boolean.FALSE; default: return null; } }
From source file:id.go.kemdikbud.tandajasa.dao.PegawaiDaoTest.java
@Test public void testInsert() throws Exception { Golongan g = new Golongan(); g.setId(99);// www . j ava2s . c o m Pegawai p = new Pegawai(); p.setNip("123"); p.setNama("Endy Muhardin"); p.setGolongan(g); DataSource ds = ctx.getBean(DataSource.class); Connection koneksiDatabase = ds.getConnection(); PreparedStatement ps = koneksiDatabase.prepareStatement("select count(*) as jumlah from pegawai"); ResultSet rsSebelum = ps.executeQuery(); Assert.assertTrue(rsSebelum.next()); Long jumlahRecordSebelum = rsSebelum.getLong(1); rsSebelum.close(); PegawaiDao pd = (PegawaiDao) ctx.getBean("pegawaiDao"); pd.save(p); ResultSet rsSetelah = ps.executeQuery(); Assert.assertTrue(rsSetelah.next()); Long jumlahRecordSetelah = rsSetelah.getLong("jumlah"); rsSetelah.close(); koneksiDatabase.close(); Assert.assertEquals(new Long(jumlahRecordSebelum + 1), new Long(jumlahRecordSetelah)); }
From source file:com.redhat.rhn.frontend.action.kickstart.KickstartPackageProfileSetupAction.java
/** * * {@inheritDoc}//from w ww.j a va 2 s. c o m */ public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) { RequestContext context = new RequestContext(request); KickstartData ks = KickstartFactory.lookupKickstartDataByIdAndOrg(context.getCurrentUser().getOrg(), context.getRequiredParam("ksid")); request.setAttribute(RequestContext.KICKSTART, ks); ListHelper helper = new ListHelper(this, request); helper.execute(); if (context.wasDispatched("kickstart.packageprofile.jsp.submit")) { String selected = ListTagHelper.getRadioSelection(helper.getListName(), request); if (StringUtils.isNumeric(selected)) { Profile prof = ProfileManager.lookupByIdAndOrg(new Long(selected), context.getCurrentUser().getOrg()); ks.getKickstartDefaults().setProfile(prof); Map<String, Object> params = new HashMap<String, Object>(); params.put("ksid", ks.getId()); getStrutsDelegate().saveMessage(UPDATE_METHOD, request); return getStrutsDelegate().forwardParams(mapping.findForward("success"), params); } } else if (context.wasDispatched("kickstart.packageprofile.jsp.clear")) { ks.getKickstartDefaults().setProfile(null); KickstartFactory.saveKickstartData(ks); request.setAttribute("ksid", ks.getId()); Map<String, Object> params = new HashMap<String, Object>(); params.put("ksid", ks.getId()); getStrutsDelegate().saveMessage(CLEAR_METHOD, request); return getStrutsDelegate().forwardParams(mapping.findForward("success"), params); } if (ks.getKickstartDefaults().getProfile() != null) { ListTagHelper.selectRadioValue(helper.getListName(), ks.getKickstartDefaults().getProfile().getId().toString(), request); } return mapping.findForward(RhnHelper.DEFAULT_FORWARD); }
From source file:org.lamop.riche.webservices.SourceRESTWS.java
@DELETE @Path("{id}") @Produces(MediaType.APPLICATION_JSON)/*from w ww.ja v a2 s. co m*/ @RequestMapping(method = RequestMethod.DELETE) public void remove(@PathParam("id") int id) { serviceSource.removeEntity(new Long(id)); }
From source file:com.boxfuse.samples.tomee.ActionServlet.java
private void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action = request.getParameter("action"); if ("Add".equals(action)) { String title = request.getParameter("title"); String director = request.getParameter("director"); String genre = request.getParameter("genre"); int rating = Integer.parseInt(request.getParameter("rating")); int year = Integer.parseInt(request.getParameter("year")); Movie movie = new Movie(title, director, genre, rating, year); moviesBean.addMovie(movie);/*from ww w .j a va 2 s. co m*/ response.sendRedirect("moviefun"); return; } else if ("Remove".equals(action)) { String[] ids = request.getParameterValues("id"); for (String id : ids) { moviesBean.deleteMovieId(new Long(id)); } response.sendRedirect("moviefun"); return; } else { String key = request.getParameter("key"); String field = request.getParameter("field"); int count = 0; if (StringUtils.isEmpty(key) || StringUtils.isEmpty(field)) { count = moviesBean.countAll(); key = ""; field = ""; } else { count = moviesBean.count(field, key); } int page = 1; try { page = Integer.parseInt(request.getParameter("page")); } catch (Exception e) { } int pageCount = (count / PAGE_SIZE); if (pageCount == 0 || count % PAGE_SIZE != 0) { pageCount++; } if (page < 1) { page = 1; } if (page > pageCount) { page = pageCount; } int start = (page - 1) * PAGE_SIZE; List<Movie> range; if (StringUtils.isEmpty(key) || StringUtils.isEmpty(field)) { range = moviesBean.findAll(start, PAGE_SIZE); } else { range = moviesBean.findRange(field, key, start, PAGE_SIZE); } int end = start + range.size(); request.setAttribute("count", count); request.setAttribute("start", start + 1); request.setAttribute("end", end); request.setAttribute("page", page); request.setAttribute("pageCount", pageCount); request.setAttribute("movies", range); request.setAttribute("key", key); request.setAttribute("field", field); } request.getRequestDispatcher("WEB-INF/moviefun.jsp").forward(request, response); }
From source file:es.udc.fic.medregatas.model.service.MangaServiceImpl.java
@Override public Manga cerrarYGuardarManga(Manga manga) { // Si la manga no est persistida if (manga.getIdManga() == null) { mangaDao.save(manga);//from ww w.jav a 2 s . com } else { mangaDao.merge(manga); } //Si las posiciones no estn persistidas for (Posicion p : manga.getPosiciones()) { if (p.getIdPosicion() == null) { posicionDao.save(p); } else { posicionDao.merge(p); } } /** * Antes de empezar a comparar puntos obtenemos los barcos registrados * en la regata y los comparamos con los que han participado en la * manga, aquellos que esten registrados y no sean anotados se les * aplicara la penalizacin DNC */ // aadimos todos los que no acabaron a posiciones de la manga for (Inscripcion i : inscripcionService.getInscripciones(manga.getRegata())) { boolean finish = false; for (Posicion p : manga.getPosiciones()) { if (p.getBarco().getVela() == i.getBarco().getVela()) { finish = true; } } if (!finish) { // TODO Con esto se aade a la lista de manga.getPosiciones() o // tenemos que hacer manualmente el add? Posicion p = new Posicion(new Long(0), Posicion.Penalizacion.DNC, manga, i.getBarco(), new Long(0)); posicionDao.save(p); manga.getPosiciones().add(p); } } //Guardamos las posiciones por tipos Map<Tipo, List<Posicion>> posPorTipo = new HashMap<Tipo, List<Posicion>>(); for (Posicion p : manga.getPosiciones()) { Tipo tipoActual = p.getBarco().getTipo(); //En caso de que no haya una entrada para ese tipo la creamos if (!posPorTipo.containsKey(tipoActual)) { posPorTipo.put(tipoActual, new ArrayList<Posicion>()); } //Aadimos la posicionActual posPorTipo.get(tipoActual).add(p); } //Para cada tipo, le asignamos puntuaciones. for (Tipo tipo : posPorTipo.keySet()) { List<Posicion> posDelTipo = posPorTipo.get(tipo); //Asignamos puntos por orden de llegada Collections.sort(posDelTipo, new Posicion.PosicionesTimeComparator()); //Asignamos los puntos comenzando en 1 for (int i = 1; i <= posDelTipo.size(); i++) { Posicion posAPuntuar = posDelTipo.get(i - 1); //El barco ha llegado a la meta if (posAPuntuar.getPenal().isMaxPointsPenal()) { //TODO Es necesario usar el dao para hacer el save?? posAPuntuar.setPuntos(posDelTipo.size() + 1); // En caso de que un barco no alcanze la meta, ser penalizado // con tantos puntos como participantes +1 } else { //TODO Es necesario usar el dao para hacer el save?? posAPuntuar.setPuntos(i); } } } //TODO esto est ok, o deberiamos de actualizar de algun modo la manga? return manga; }
From source file:NumberUtil.java
/** * Convert an Object to a Long.//w w w.j a va 2 s . c o m */ public static Long toLong(Object value) { if (value == null) return null; if (value instanceof Long) return (Long) value; if (value instanceof String) { if ("".equals((String) value)) return null; return new Long((String) value); } if (value instanceof Number) return new Long(((Number) value).shortValue()); return new Long(value.toString()); }
From source file:test.gov.nih.nci.cacoresdk.domain.operations.SpecimenCollectionGroupResourceTest.java
/** * Uses Nested Search Criteria for search * Verifies that the results are returned * Verifies size of the result set/*from w w w .j av a 2s .c o m*/ * Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { SpecimenCollectionGroup searchObject = new SpecimenCollectionGroup(); Collection results = getApplicationService() .search("gov.nih.nci.cacoresdk.domain.operations.SpecimenCollectionGroup", searchObject); String id = ""; if (results != null && results.size() > 0) { SpecimenCollectionGroup obj = (SpecimenCollectionGroup) ((List) results).get(0); Long idVal = obj.getId(); id = new Long(idVal).toString(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/SpecimenCollectionGroup/" + id; WebClient client = WebClient.create(url); client.type("application/xml").accept("application/xml"); Response response = client.get(); if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } File myFile = new File("SpecimenCollectionGroup" + "XML.xml"); System.out.println("writing data to file " + myFile.getAbsolutePath()); FileWriter myWriter = new FileWriter(myFile); BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream) response.getEntity()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { myWriter.write(output); System.out.println(output); } myWriter.flush(); myWriter.close(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:net.sf.sail.webapp.dao.sds.impl.SdsOfferingGetCommandHttpRestImpl.java
/** * @see net.sf.sail.webapp.dao.sds.SdsCommand#execute() *///from www . j av a2s . c o m @SuppressWarnings("unchecked") public SdsOffering execute(HttpGetRequest httpRequest) throws CurnitMapNotFoundException { // TODO LAW check on thread safety of these method final SdsOffering sdsOffering = this.getSdsOffering(); SDS_OFFERING.set(null); Document doc = convertXmlInputStreamToXmlDocument(this.transport.get(httpRequest)); if (doc == null) { return sdsOffering; } Element sdsOfferingElement = doc.getRootElement(); sdsOffering.setName(sdsOfferingElement.getChild("name").getValue()); sdsOffering.setSdsObjectId(new Long(sdsOfferingElement.getChild("id").getValue())); SdsCurnit sdsCurnit = new SdsCurnit(); sdsCurnit.setSdsObjectId(new Long(sdsOfferingElement.getChild("curnit-id").getValue())); sdsOffering.setSdsCurnit(sdsCurnit); SdsJnlp sdsJnlp = new SdsJnlp(); sdsJnlp.setSdsObjectId(new Long(sdsOfferingElement.getChild("jnlp-id").getValue())); sdsOffering.setSdsJnlp(sdsJnlp); curnitMapGetter.setSdsOfferingCurnitMap(sdsOffering); return sdsOffering; }