public List<DataUpload> getImports() { Organization org = DB.getOrganizationDAO().findById(this.organizationId, false); List<DataUpload> du = new ArrayList<DataUpload>(); if (this.userId > -1) { User u = DB.getUserDAO().findById(userId, false); du = DB.getDataUploadDAO().findByOrganizationUser(org, u); // check transform status and set boolean here return du; } du = DB.getDataUploadDAO().findByOrganization(org); if (du == null) return Collections.emptyList(); // log.debug("startImport:"+startImport+" maxImports:"+maxImports); return du; }
/** * Select which uploads are involved in this item Panel call Use it to retrieve items or item * count !! 3 cases: - For a specific upload: the uploadID > 1 - For an organization all items * (the "normal" case) organizationId > -1 userId == -1 - For a specific user in an org: * organizationId and userId > -1 * * @return */ private List<DataUpload> findUploads() { List<DataUpload> result = Collections.emptyList(); if (getUploadId() > -1) { log.debug("Items by Upload " + uploadId); result = new ArrayList<DataUpload>(); DataUpload du = DB.getDataUploadDAO().getById(getUploadId(), false); result.add(du); } else { Organization org = DB.getOrganizationDAO().findById(organizationId, false); if (org != null) { if (getUserId() > -1) { log.debug("Items by User " + userId + " and Org " + organizationId); User user = DB.getUserDAO().findById(this.userId, false); result = DB.getDataUploadDAO().getByUserOrg(user, org); } else { log.debug("Items by Org " + organizationId); result = org.getDataUploads(); } } } return result; }
@Action(value = "AjaxApproval") public String execute() throws Exception { PrintWriter writer = null; try { writer = response.getWriter(); } catch (IOException ex) { System.out.println( AjaxFileReader.class.getName() + "has thrown an exception: " + ex.getMessage()); } try { Long dbID = Long.parseLong(request.getParameter("id")); DataUpload du = DB.getDataUploadDAO().getById(dbID, false); tr = DB.getTransformationDAO().findOneByUpload(du); // new version of the transformation for this session if (tr == null) { return ERROR; } else { tr.setIsApproved(Integer.parseInt(request.getParameter("approved"))); DB.commit(); String urlParameters = request.getParameter("id") + "/" + request.getParameter("approved") + '/' + user.getDbID(); log.debug("Parameters " + urlParameters); String request = "https://ams.americanarchive.org/mintimport/update_transformed_info/" + urlParameters; log.debug("Request URL " + request); URL url = new URL(request); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setUseCaches(false); connection.setAllowUserInteraction(false); connection.setDoOutput(true); connection.setReadTimeout(10000); connection.setRequestMethod("GET"); connection.setRequestProperty("charset", "utf-8"); connection.setUseCaches(false); connection.connect(); int responseCode = connection.getResponseCode(); log.debug("Response Code " + responseCode); log.debug("Nouman Tayyab Bokhari"); BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder sb = new StringBuilder(); String line = ""; while ((line = rd.readLine()) != null) { sb.append(line + '\n'); } System.out.println(sb.toString()); connection.disconnect(); } } catch (Exception e) { // already handled, but needed to skip readNodes or index if transform or readNodes fails } catch (Throwable t) { writer.print("uhh " + t); } response.setStatus(HttpServletResponse.SC_OK); writer.flush(); writer.close(); return "success"; }