コード例 #1
0
ファイル: ParameterizedNode.java プロジェクト: jpaulptr/galen
  private Table buildFromChild(VarsContext context) {
    Table table = new Table();

    for (Node<?> childNode : getChildNodes()) {
      if (childNode instanceof TableRowNode) {
        TableRowNode row = (TableRowNode) childNode;
        try {
          table.addRow(row.build(context));
        } catch (SyntaxException e) {
          throw new SyntaxException(row.getLine(), e.getMessage());
        }
      }
    }
    return table;
  }
コード例 #2
0
ファイル: UploadStep.java プロジェクト: atmire/RIOXX52
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    // If we are actually editing information of an uploaded file,
    // then display that body instead!
    if (this.editFile != null) {
      editFile.addBody(body);
      return;
    }

    // Get a list of all files in the original bundle
    Item item = submission.getItem();
    Collection collection = submission.getCollection();
    String actionURL =
        contextPath + "/handle/" + collection.getHandle() + "/submit/" + knot.getId() + ".continue";
    boolean disableFileEditing =
        (submissionInfo.isInWorkflow())
            && !ConfigurationManager.getBooleanProperty("workflow", "reviewer.file-edit");
    Bundle[] bundles = item.getBundles("ORIGINAL");
    Bitstream[] bitstreams = new Bitstream[0];
    if (bundles.length > 0) {
      bitstreams = bundles[0].getBitstreams();
    }

    // Part A:
    //  First ask the user if they would like to upload a new file (may be the first one)
    Division div =
        body.addInteractiveDivision(
            "submit-upload", actionURL, Division.METHOD_MULTIPART, "primary submission");
    div.setHead(T_submission_head);
    addSubmissionProgressList(div);

    List upload = null;
    if (!disableFileEditing) {
      // Only add the upload capabilities for new item submissions
      upload = div.addList("submit-upload-new", List.TYPE_FORM);
      upload.setHead(T_head);
      addRioxxVersionSection(upload, item);

      File file = upload.addItem().addFile("file");
      file.setLabel(T_file);
      file.setHelp(T_file_help);
      file.setRequired();

      // if no files found error was thrown by processing class, display it!
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_NO_FILES_ERROR) {
        file.addError(T_file_error);
      }

      // if an upload error was thrown by processing class, display it!
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_UPLOAD_ERROR) {
        file.addError(T_upload_error);
      }

      // if virus checking was attempted and failed in error then let the user know
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_VIRUS_CHECKER_UNAVAILABLE) {
        file.addError(T_virus_checker_error);
      }

      // if virus checking was attempted and a virus found then let the user know
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_CONTAINS_VIRUS) {
        file.addError(T_virus_error);
      }

      Text description = upload.addItem().addText("description");
      description.setLabel(T_description);
      description.setHelp(T_description_help);

      Button uploadSubmit = upload.addItem().addButton("submit_upload");
      uploadSubmit.setValue(T_submit_upload);
    }

    make_sherpaRomeo_submission(item, div);

    // Part B:
    //  If the user has already uploaded files provide a list for the user.
    if (bitstreams.length > 0 || disableFileEditing) {
      Table summary = div.addTable("submit-upload-summary", (bitstreams.length * 2) + 2, 7);
      summary.setHead(T_head2);

      Row header = summary.addRow(Row.ROLE_HEADER);
      header.addCellContent(T_column0); // primary bitstream
      header.addCellContent(T_column1); // select checkbox
      header.addCellContent(T_column2); // file name
      header.addCellContent(T_column3); // size
      header.addCellContent(T_column4); // description
      header.addCellContent(T_column5); // format
      header.addCellContent(T_column6); // edit button

      for (Bitstream bitstream : bitstreams) {
        int id = bitstream.getID();
        String name = bitstream.getName();
        String url = makeBitstreamLink(item, bitstream);
        long bytes = bitstream.getSize();
        String desc = bitstream.getDescription();
        String algorithm = bitstream.getChecksumAlgorithm();
        String checksum = bitstream.getChecksum();

        Row row = summary.addRow();

        // Add radio-button to select this as the primary bitstream
        Radio primary = row.addCell().addRadio("primary_bitstream_id");
        primary.addOption(String.valueOf(id));

        // If this bitstream is already marked as the primary bitstream
        // mark it as such.
        if (bundles[0].getPrimaryBitstreamID() == id) {
          primary.setOptionSelected(String.valueOf(id));
        }

        if (!disableFileEditing) {
          // Workflow users can not remove files.
          CheckBox remove = row.addCell().addCheckBox("remove");
          remove.setLabel("remove");
          remove.addOption(id);
        } else {
          row.addCell();
        }

        row.addCell().addXref(url, name);
        row.addCellContent(bytes + " bytes");
        if (desc == null || desc.length() == 0) {
          row.addCellContent(T_unknown_name);
        } else {
          row.addCellContent(desc);
        }

        BitstreamFormat format = bitstream.getFormat();
        if (format == null) {
          row.addCellContent(T_unknown_format);
        } else {
          int support = format.getSupportLevel();
          Cell cell = row.addCell();
          cell.addContent(format.getMIMEType());
          cell.addContent(" ");
          switch (support) {
            case 1:
              cell.addContent(T_supported);
              break;
            case 2:
              cell.addContent(T_known);
              break;
            case 3:
              cell.addContent(T_unsupported);
              break;
          }
        }

        Button edit = row.addCell().addButton("submit_edit_" + id);
        edit.setValue(T_submit_edit);

        Row checksumRow = summary.addRow();
        checksumRow.addCell();
        Cell checksumCell = checksumRow.addCell(null, null, 0, 6, null);
        checksumCell.addHighlight("bold").addContent(T_checksum);
        checksumCell.addContent(" ");
        checksumCell.addContent(algorithm + ":" + checksum);
      }

      if (!disableFileEditing) {
        // Workflow users can not remove files.
        Row actionRow = summary.addRow();
        actionRow.addCell();
        Button removeSeleceted =
            actionRow.addCell(null, null, 0, 6, null).addButton("submit_remove_selected");
        removeSeleceted.setValue(T_submit_remove);
      }

      upload = div.addList("submit-upload-new-part2", List.TYPE_FORM);
    }

    // Part C:
    // add standard control/paging buttons
    addControlButtons(upload);
  }
コード例 #3
0
ファイル: BrowseFacet.java プロジェクト: Numf/dspace
  @Override
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {

    Request request = ObjectModelHelper.getRequest(objectModel);

    DSpaceObject dso = HandleUtil.obtainHandle(objectModel);

    // Set up the major variables
    // Collection collection = (Collection) dso;

    // Build the collection viewer division.

    // Make sure we get our results
    queryResults = getQueryResponse(dso);
    if (this.queryResults != null) {

      Map<String, List<DiscoverResult.FacetResult>> facetFields =
          this.queryResults.getFacetResults();
      if (facetFields == null) {
        facetFields = new LinkedHashMap<String, List<DiscoverResult.FacetResult>>();
      }

      //            facetFields.addAll(this.queryResults.getFacetDates());

      if (facetFields.size() > 0) {
        String facetField =
            String.valueOf(facetFields.keySet().toArray(new String[facetFields.size()])[0]);
        java.util.List<DiscoverResult.FacetResult> values = facetFields.get(facetField);

        if (values != null && 0 < values.size()) {

          Division results = body.addDivision("browse-by-" + facetField + "-results", "primary");

          results.setHead(
              message(
                  "xmlui.ArtifactBrowser.AbstractSearch.type_"
                      + request.getParameter(FACET_FIELD)
                      + "_browse"));

          // Find our faceting offset
          int offSet = queryArgs.getFacetOffset();
          if (offSet == -1) {
            offSet = 0;
          }

          // Only show the nextpageurl if we have at least one result following our current results
          String nextPageUrl = null;
          if (values.size() == (DEFAULT_PAGE_SIZE + 1)) {
            nextPageUrl = getNextPageURL(request);
          }

          results.setSimplePagination(
              (int) queryResults.getDspaceObjects().size(),
              offSet + 1,
              (offSet + (values.size() - 1)),
              getPreviousPageURL(request),
              nextPageUrl);

          Table singleTable =
              results.addTable(
                  "browse-by-" + facetField + "-results",
                  (int) (queryResults.getDspaceObjects().size() + 1),
                  1);

          List<String> filterQueries = new ArrayList<String>();
          if (request.getParameterValues("fq") != null) {
            filterQueries = Arrays.asList(request.getParameterValues("fq"));
          }
          for (int i = 0; i < values.size(); i++) {
            DiscoverResult.FacetResult value = values.get(i);

            String displayedValue = value.getDisplayedValue();
            String filterQuery = value.getAsFilterQuery();

            //                        if(field.getGap() != null){
            //                            //We have a date get the year so we can display it
            //                            DateFormat simpleDateformat = new
            // SimpleDateFormat("yyyy");
            //                            displayedValue =
            // simpleDateformat.format(SolrServiceImpl.toDate(displayedValue));
            //                            filterQuery =
            // ClientUtils.escapeQueryChars(value.getFacetField().getName()) + ":" + displayedValue
            // + "*";
            //                        }

            Cell cell = singleTable.addRow().addCell();

            // No use in selecting the same filter twice
            if (filterQueries.contains(filterQuery)) {
              cell.addContent(displayedValue + " (" + value.getCount() + ")");
            } else {
              cell.addXref(
                  contextPath
                      + (dso == null ? "" : "/handle/" + dso.getHandle())
                      + "/discover?"
                      + "&fq="
                      + URLEncoder.encode(filterQuery, "UTF-8")
                      + (request.getQueryString() != null ? "&" + request.getQueryString() : ""),
                  displayedValue + " (" + value.getCount() + ")");
            }
          }
        }
      }
    }

    // DSpaceObject dso = HandleUtil.obtainHandle(objectModel);

    /*
    if (dso != null)
    {
        if (dso instanceof Collection)
        {
            browseContext.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2+AND+location%3Al" + dso.getID(), T_head_this_collection );
        }
        if (dso instanceof Community)
        {
            browseContext.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2+AND+location%3Am" + dso.getID(), T_head_this_community );
        }
    }

    browseGlobal.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2", T_head_all_of_dspace );
    */
  }
コード例 #4
0
  @Override
  public void generateAccess(
      String accessFilename,
      int rowCount,
      List<FieldDefinition> fieldDefinitionList,
      int tableCount) {

    long startTime = new Date().getTime();

    outputWriterHolder.writeValueInLine("Access data generation started");
    Database db = null;

    try {
      db = DatabaseBuilder.create(Database.FileFormat.V2010, new File(accessFilename));
      // New table
      int columnCount = fieldDefinitionList.size();

      // Create Hash Map of Field Definitions
      Map<Integer, Input2TableInfo> input2TableInfoMap = new LinkedHashMap<>(columnCount);
      Map<Table, List<Object[]>> tableToGeneratedData = new HashMap<>();

      for (int i = 0; i < columnCount; i++) {
        Input2TableInfo input2TableInfo = new Input2TableInfo();
        FieldDefinition fieldDefinition = fieldDefinitionList.get(i);
        input2TableInfo.setFieldText(fieldDefinition.getFieldName());
        input2TableInfo.setFieldDefinition(fieldDefinition);
        input2TableInfo.initGenerator();
        input2TableInfoMap.put(i, input2TableInfo);
      }

      if (tableCount > 1) {
        List<Table> tableListForGeneration = new ArrayList<>();
        for (int i = 0; i < tableCount; i++) {
          TableBuilder tableBuilder = new TableBuilder("dataTable_" + i);
          for (Integer key : input2TableInfoMap.keySet()) {
            Input2TableInfo input2TableInfo = input2TableInfoMap.get(key);
            tableBuilder.addColumn(
                new ColumnBuilder(input2TableInfo.getFieldText())
                    .setSQLType(getType(input2TableInfo.getFieldDefinition().getType())));
          }
          tableListForGeneration.add(tableBuilder.toTable(db));
        }

        CountDownLatch startSignal = new CountDownLatch(1);
        CountDownLatch doneSignal;

        doneSignal = new CountDownLatch(tableCount);

        ParameterVault parameterVault = new DefaultParameterVault(0, rowCount);
        TableProcessor tableProcessor1 =
            new TableProcessor(
                parameterVault,
                startSignal,
                doneSignal,
                tableListForGeneration.get(0),
                columnCount,
                input2TableInfoMap,
                outputWriterHolder,
                tableToGeneratedData);
        new Thread(tableProcessor1, "Processor-" + tableCount).start();

        for (int i = 1; i < tableCount; i++) {
          ParameterVault parameterVaultRest = new DefaultParameterVault(i, rowCount);
          TableProcessor tableProcessor =
              new TableProcessor(
                  parameterVaultRest,
                  startSignal,
                  doneSignal,
                  tableListForGeneration.get(i),
                  columnCount,
                  input2TableInfoMap,
                  outputWriterHolder,
                  tableToGeneratedData);
          new Thread(tableProcessor, "Processor-" + i).start();
        }

        startSignal.countDown();
        doneSignal.await();
      } else {
        TableBuilder tableBuilder = new TableBuilder("dataTable_0");
        for (Integer key : input2TableInfoMap.keySet()) {
          Input2TableInfo input2TableInfo = input2TableInfoMap.get(key);
          tableBuilder.addColumn(
              new ColumnBuilder(input2TableInfo.getFieldText())
                  .setSQLType(getType(input2TableInfo.getFieldDefinition().getType())));
        }
        ParameterVault parameterVault = new DefaultParameterVault(0, rowCount);
        new TableProcessor(outputWriterHolder)
            .generateTableData(
                parameterVault,
                tableBuilder.toTable(db),
                columnCount,
                input2TableInfoMap,
                tableToGeneratedData);
      }

      outputWriterHolder.writeValueInLine("Access data generation finished.");
      long generationTime = new Date().getTime();
      outputWriterHolder.writeValueInLine(
          "Time used " + ((generationTime - startTime) / 1000) + " sec");
      outputWriterHolder.writeValueInLine("Writing to file.");

      for (Map.Entry<Table, List<Object[]>> tableListEntry : tableToGeneratedData.entrySet()) {
        Table table = tableListEntry.getKey();
        List<Object[]> rowListForTable = tableListEntry.getValue();
        for (Object[] row : rowListForTable) {
          table.addRow(row);
        }
      }

      long writeTime = new Date().getTime();
      outputWriterHolder.writeValueInLine(
          "Time used " + ((writeTime - generationTime) / 1000) + " sec");
      outputWriterHolder.writeValueInLine(
          "Total time used " + ((writeTime - startTime) / 1000) + " sec");
      outputWriterHolder.writeValueInLine("Done");
    } catch (Exception e) {
      LOGGER.error(e.getMessage(), e);
    } finally {
      try {
        if (db != null) {
          db.close();
        }
      } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
      }
    }
  }