Beispiel #1
0
  @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";
  }
Beispiel #2
0
  /**
   * All items for given list of uploads. Respect startItem and maxItem
   *
   * @param uploads
   * @return
   */
  private List<Item> itemsByUploads(List<DataUpload> uploads) {

    if (resultItemList != null) return resultItemList;
    resultItemList = new ArrayList<Item>();
    long currentStart = 0l;
    int itemsRead = 0;
    boolean transform = false;
    for (DataUpload du : uploads) {
      transform = false;
      if (du.getItemXpath() != null) {
        if (DB.getTransformationDAO().findByUpload(du).size() > 0) {
          if (DB.getTransformationDAO().findByUpload(du).get(0).getStatusCode() == 0)
            transform = true;
        }
        if (currentStart + du.getItemXpath().getCount() < startItem) {
          currentStart += du.getItemXpath().getCount();
          continue;
        }
        List<XMLNode> l =
            du.getItemXpath().getNodes(startItem + itemsRead - currentStart, maxItems);
        for (XMLNode x : l) {
          log.debug("get tree .. ");
          XMLNode tree = DB.getXMLNodeDAO().getDOMTree(x);
          boolean trunc = false;
          if (tree.getSize() > 20000) {
            trunc = true;
          }

          log.debug(" . done");
          if (itemsRead < maxItems) {
            List<? extends XMLNode> labelList = tree.getChildrenByXpath(du.getItemLabelXpath());
            if (labelList.size() != 1) log.warn("Label not unique");

            XMLNode label;
            Item i = new Item();
            if (labelList.size() == 1) {
              label = labelList.get(0);
              i.name = label.getContent();
            } else if (labelList.size() == 0) {
              i.name = "<no label>";
            } else {
              i.name = "<" + labelList.size() + " labels>";
            }
            i.truncated = trunc;
            i.uploadId = du.getDbID();
            i.direct = du.isDirect();
            i.nodeId = x.getNodeId();
            i.transformed = transform;
            if (du.getUploadDate() == null) i.itemdate = "";
            else i.itemdate = new SimpleDateFormat("dd/MM/yyyy HH:mm").format(du.getUploadDate());
            i.importname = du.getOriginalFilename();
            /*if( du.getOriginalFilename().length()<15 )
            	i.importname=du.getOriginalFilename();
            else
            	i.importname=".."+du.getOriginalFilename()
            	.substring(du.getOriginalFilename().length()-12);
            	 */
            resultItemList.add(i);
            itemsRead += 1;
            log.debug("adding item:" + itemsRead + " with date:" + i.getDate());
          }
        }
        if (itemsRead == maxItems) break;
        currentStart += du.getItemXpath().getCount();
      }
    }
    endItem = startItem + resultItemList.size();
    return resultItemList;
  }