/**
   * Creates instance of editor.
   *
   * @param harvestRepository repository to be edited
   */
  public HarvestEditor(HrRecord harvestRepository) {
    _harvestRepository = harvestRepository;
    protocols.put(harvestRepository.getProtocol().getKind(), harvestRepository.getProtocol());

    ApplicationContext appCtx = ApplicationContext.getInstance();
    ApplicationConfiguration appCfg = appCtx.getConfiguration();

    String sArcgisDotComAllowed =
        appCfg
            .getCatalogConfiguration()
            .getParameters()
            .getValue("webharvester.agp2agp.arcgisDotCom.allowed");
    this.arcgisDotComAllowed = Val.chkBool(sArcgisDotComAllowed, false);

    String sCrossAllowed =
        appCfg
            .getCatalogConfiguration()
            .getParameters()
            .getValue("webharvester.agp2agp.sameDomain.allowed");
    this.crossAllowed = Val.chkBool(sCrossAllowed, false);
  }
  /**
   * Sets the extra criteria properties. Properties unique to using this writer. Currently gets the
   * rids and the ridName attribute.
   *
   * @pa ram httpReq the new extra criteria properties
   */
  private void setExtraCriteriaProperties(HttpServletRequest httpReq) {
    String rids = httpReq.getParameter("rids");
    String ridName = httpReq.getParameter("ridName");

    SearchCriteria criteria = this.getCriteria();
    SearchFiltersList filters = criteria.getMiscelleniousFilters();
    for (ISearchFilter filter : filters) {
      if (filter instanceof SearchFilterHarvestSites) {
        SearchFilterHarvestSites sfHs = (SearchFilterHarvestSites) filter;
        sfHs.setSelectedDistributedIds(rids);
        sfHs.setSelectedHarvestSiteName(ridName);
      }
    }

    boolean expandResults = Val.chkBool(httpReq.getParameter("expandResults"), false);
    criteria.setExpandResultContent(expandResults);
  }
Esempio n. 3
0
  /**
   * Reads record data.
   *
   * @param rs result set to read from
   * @param record record to write to
   * @throws SQLException if accessing database fails
   * @throws ParserConfigurationException if unable to reach parser configuration
   * @throws IOException if unable to perform IO operation
   * @throws SAXException if unable to parse XML data
   */
  private void readRecord(ResultSet rs, MmdRecord record)
      throws SQLException, ParserConfigurationException, IOException, SAXException {
    int n = 1;

    // set the title and uuid
    record.setTitle(rs.getString(n++));
    record.setUuid(rs.getString(n++));
    record.setSiteUuid(rs.getString(n++));
    if (getActionCriteria().getSelectedRecordIdSet().contains(record.getUuid())) {
      record.setIsSelected(true);
    }

    // set the owner, approval status and publication method
    record.setOwnerName(rs.getString(n++));
    record.setApprovalStatus(rs.getString(n++));
    record.setPublicationMethod(rs.getString(n++));

    // set the update date,
    Timestamp ts = rs.getTimestamp(n++);
    if (ts != null) {
      record.setSystemUpdateDate(ts);
      record.setFormattedUpdateDate(DateProxy.formatDate(ts));
    }

    // set the ACL
    String aclXml = rs.getString(n++);
    if (aclXml != null && aclXml.trim().length() > 0) {
      record.setMetadataAccessPolicyType("Restricted");
      MetadataAcl acl = new MetadataAcl(getRequestContext());
      record.setCurrentMetadataAccessPolicy(acl.makeGroupsfromXml(allGroups, aclXml));
      record.setCurrentMetadataAccessPolicyKeys(acl.makeGroupsKeysfromXml(allGroups, aclXml));
    } else {
      record.setMetadataAccessPolicyType("Unrestricted");
      record.setCurrentMetadataAccessPolicy("Unrestricted");
      record.setCurrentMetadataAccessPolicyKeys("Unrestricted");
    }

    // set harvesting specific data
    record.setLocalId(rs.getInt(n++));
    record.setHostUrl(rs.getString(n++));
    String frequency = Val.chkStr(rs.getString(n++));
    if (frequency.length() > 0)
      record.setHarvestFrequency(HarvestFrequency.checkValueOf(frequency));
    record.setSendNotification(Val.chkBool(rs.getString(n++), false));
    String protocol = Val.chkStr(rs.getString(n++));
    if (protocol.length() > 0)
      record.setProtocol(
          getApplicationConfiguration().getProtocolFactories().parseProtocol(protocol));

    // set the editable status
    boolean isEditor =
        record.getPublicationMethod().equalsIgnoreCase(PublicationMethod.editor.name());
    boolean isSEditor =
        record.getPublicationMethod().equalsIgnoreCase(PublicationMethod.seditor.name());
    boolean isProtocol = record.getProtocol() != null;
    boolean isOwner = hmEditablePublishers.containsKey(record.getOwnerName().toLowerCase());
    record.setCanEdit(
        (isEditor || isSEditor || isProtocol) && (isOwner || (isProtocol && isGptAdministrator)));

    // TODO remove as this is a temporary fix
    boolean isOther =
        record.getPublicationMethod().equalsIgnoreCase(PublicationMethod.other.name());
    if (isOther && isProtocol) {
      record.setPublicationMethod(PublicationMethod.registration.name());
    }

    record.setFindable(Val.chkBool(rs.getString(n++), false));
    record.setSearchable(Val.chkBool(rs.getString(n++), false));
    record.setSynchronizable(Val.chkBool(rs.getString(n++), false));
  }
 /**
  * Sets sending notification switch flag.
  *
  * @param sendNotification sending notification switch flag
  */
 public void setSendNotification(String sendNotification) {
   _harvestRepository.setSendNotification(Val.chkBool(sendNotification, false));
 }
  /**
   * Performs search operation.
   *
   * @param request HTTP servlet request
   * @param response HTTP servlet response
   * @param context request context
   * @param query query
   * @return records
   * @throws Exception if searching fails
   */
  @Override
  public IFeedRecords doSearch(
      HttpServletRequest request,
      HttpServletResponse response,
      RequestContext context,
      RestQuery query)
      throws Exception {
    MessageBroker msgBroker = new FacesContextBroker(request, response).extractMessageBroker();
    final Map<DiscoveredRecord, Map<String, List<String>>> mapping =
        new HashMap<DiscoveredRecord, Map<String, List<String>>>();

    List<IFeedRecords.FieldMeta> fields = new ArrayList<IFeedRecords.FieldMeta>();
    loadStdFieldMeta(fields);

    int startRecord = query.getFilter().getStartRecord();
    boolean returnIdsOnly = Val.chkBool(Val.chkStr(request.getParameter("returnIdsOnly")), false);
    if (returnIdsOnly) {
      startRecord = 1;
      query.getFilter().setMaxRecords(1);
      LuceneQueryAdapter tmp = new LuceneQueryAdapter();
      tmp.execute(context, query);
      query.getFilter().setMaxRecords(query.getResult().getNumberOfHits());
    }

    query.getFilter().setStartRecord(startRecord);
    LuceneQueryAdapter lqa =
        new LuceneQueryAdapter() {
          @Override
          protected void onRecord(DiscoveredRecord record, Document document) {
            Map<String, List<String>> fieldMap = new HashMap<String, List<String>>();
            for (Fieldable field : document.getFields()) {
              String name = field.name();
              List<String> fieldValues = fieldMap.get(name);
              if (fieldValues == null) {
                fieldValues = new ArrayList<String>();
                fieldMap.put(name, fieldValues);
              }
              fieldValues.add(field.stringValue());
            }
            mapping.put(record, fieldMap);
          }
        };
    lqa.execute(context, query);
    startRecord += query.getFilter().getMaxRecords();

    loadLuceneMeta(context, fields);

    OpenSearchProperties osProps = new OpenSearchProperties();
    osProps.setShortName(msgBroker.retrieveMessage("catalog.openSearch.shortName"));
    osProps.setNumberOfHits(query.getResult().getNumberOfHits());
    osProps.setStartRecord(query.getFilter().getStartRecord());
    osProps.setRecordsPerPage(query.getFilter().getMaxRecords());

    ResourceIdentifier resourceIdentifier = ResourceIdentifier.newIdentifier(context);
    DiscoveredRecordsAdapter discoveredRecordsAdapter =
        new DiscoveredRecordsAdapter(
            resourceIdentifier, osProps, fields, query.getResult().getRecords(), mapping);

    FeedLinkBuilder linkBuilder =
        new FeedLinkBuilder(context, RequestContext.resolveBaseContextPath(request), msgBroker);
    for (IFeedRecord record : discoveredRecordsAdapter) {
      linkBuilder.build(record);
    }

    return discoveredRecordsAdapter;
    /*
    MessageBroker msgBroker = new FacesContextBroker(request, response).extractMessageBroker();
    FeedLinkBuilder linkBuilder = new FeedLinkBuilder(RequestContext.resolveBaseContextPath(request), msgBroker);

    DcatRecordsAdapter discoveredRecordsAdapter = new DcatRecordsAdapter(msgBroker, linkBuilder, context, query);

    return discoveredRecordsAdapter;
    */
  }