コード例 #1
0
ファイル: Harvester.java プロジェクト: rkachelriess/Geoportal
 /**
  * Submits new harvesting task for partial harvest.
  *
  * @param context request context
  * @param resource resource to harvest
  * @param maxRecs maximum number of records to harvest (<code>null</code> for no maximum limit)
  * @param fromDate to harvest only from the specific date (<code>null</code> for no from date)
  * @return <code>true</code> if task has been submitted
  */
 public boolean submit(RequestContext context, HrRecord resource, Integer maxRecs, Date fromDate) {
   if (resource == null) throw new IllegalArgumentException("No resource to harvest provided.");
   // create instance of the task
   // add only if no similar task currently executing
   boolean submitted = false;
   if (ApprovalStatus.isPubliclyVisible(resource.getApprovalStatus().name())
       && resource.getSynchronizable()) {
     CommonCriteria criteria = new CommonCriteria();
     criteria.setMaxRecords(maxRecs);
     if (fromDate != null) {
       Calendar cal = Calendar.getInstance();
       cal.setTime(fromDate);
       cal.set(Calendar.HOUR_OF_DAY, 0);
       cal.set(Calendar.MINUTE, 0);
       cal.set(Calendar.SECOND, 0);
       cal.set(Calendar.MILLISECOND, 0);
       fromDate = cal.getTime();
     }
     criteria.setFromDate(fromDate);
     submitted =
         !isExecutingLocally(resource.getUuid())
             && (taskQueue != null ? taskQueue.add(context, resource, criteria) : false);
     LOGGER.log(
         Level.FINER,
         "[SYNCHRONIZER] Submitted resource: {0} ({1})",
         new Object[] {resource.getUuid(), resource.getName()});
   }
   return submitted;
 }
コード例 #2
0
  /**
   * 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);
  }
コード例 #3
0
ファイル: Harvester.java プロジェクト: rkachelriess/Geoportal
 /**
  * Spans new, separate thread exclusively for the resource.
  *
  * @param context request context
  * @param resource resource to harvest
  * @param maxRecs maximum number of records to harvest (<code>null</code> for no maximum limit)
  * @param fromDate to harvest only from the specific date (<code>null</code> for no from date)
  * @return <code>true</code> if task has been sumbited
  */
 public boolean span(RequestContext context, HrRecord resource, Integer maxRecs, Date fromDate) {
   if (resource == null) throw new IllegalArgumentException("No resource to harvest provided.");
   // create instance of the task
   // add only if no similar task currently executing
   boolean submitted = false;
   if (resource.getApprovalStatus() == ApprovalStatus.approved && resource.getSynchronizable()) {
     CommonCriteria criteria = new CommonCriteria();
     criteria.setMaxRecords(maxRecs);
     criteria.setFromDate(fromDate);
     submitted =
         pool != null && taskQueue != null
             ? !pool.isExecuting(resource.getUuid())
                 && taskQueue.register(context, resource, criteria)
             : false;
     if (submitted) pool.span(resource, criteria);
     LOGGER.log(
         Level.FINER,
         "[SYNCHRONIZER] Submitted resource: {0} ({1})",
         new Object[] {resource.getUuid(), resource.getName()});
   }
   return submitted;
 }
コード例 #4
0
 /**
  * Gets host URL.
  *
  * @return host URL
  */
 public String getHostUrl() {
   return _harvestRepository.getHostUrl();
 }
コード例 #5
0
 /**
  * Gets repository name.
  *
  * @return name
  */
 public String getName() {
   return _harvestRepository.getName();
 }
コード例 #6
0
 /**
  * Sets repository name.
  *
  * @param name name
  */
 public void setName(String name) {
   _harvestRepository.setName(name);
 }
コード例 #7
0
 /**
  * Sets time codes.
  *
  * @param timeCodes time codes
  */
 public void setTimeCodes(String timeCodes) {
   _harvestRepository.getProtocol().setAdHoc(timeCodes);
 }
コード例 #8
0
 /**
  * Checks if 'deep harvest' is enabled.
  *
  * @return <code>true</code> if 'deep harvest' is enabled
  */
 public boolean getUpdateContent() {
   return ProtocolInvoker.getUpdateContent(_harvestRepository.getProtocol());
 }
コード例 #9
0
 /**
  * Sets SOAP URL.
  *
  * @param url SOAP URL
  */
 public void setSoapUrl(String url) {
   if (_harvestRepository.getProtocol() instanceof ArcGISProtocol) {
     ((ArcGISProtocol) _harvestRepository.getProtocol()).setSoapUrl(url);
   }
 }
コード例 #10
0
 /**
  * Gets string representation of the object.
  *
  * @return string representation
  */
 @Override
 public String toString() {
   return _harvestRepository.toString();
 }
コード例 #11
0
 /**
  * Checks if 'lock-title' is enabled. If a flag is set, it means a title is locked and
  * synchronizer is not allowed to update it, although all the rest of information is allowed to be
  * updated.
  *
  * @return <code>true</code> if 'lock-title' is enabled
  */
 public boolean getLockTitle() {
   return ProtocolInvoker.getLockTitle(_harvestRepository.getProtocol());
 }
コード例 #12
0
 /**
  * Enables/disables 'lock-title' If a flag is set, it means a title is locked and synchronizer is
  * not allowed to update it, although all the rest of information is allowed to be updated.
  *
  * @param lockTitle <code>true</code> to enable 'lock-title'
  */
 public void setLockTitle(boolean lockTitle) {
   ProtocolInvoker.setLockTitle(_harvestRepository.getProtocol(), lockTitle);
 }
コード例 #13
0
 /**
  * Checks if 'auto-approve' is enabled.
  *
  * @return <code>true</code> if 'auto-approve' is enabled
  */
 public boolean getAutoApprove() {
   return ProtocolInvoker.getAutoApprove(_harvestRepository.getProtocol());
 }
コード例 #14
0
 /**
  * Enables/disables 'auto-approve'
  *
  * @param enabled <code>true</code> to enable 'auto-approve'
  */
 public void setAutoApprove(boolean enabled) {
   ProtocolInvoker.setAutoApprove(_harvestRepository.getProtocol(), enabled);
 }
コード例 #15
0
 /**
  * Enables/disables 'xml generation'
  *
  * @param enabled <code>true</code> to enable 'xml generation'
  */
 public void setUpdateDefinition(boolean enabled) {
   ProtocolInvoker.setUpdateDefinition(_harvestRepository.getProtocol(), enabled);
 }
コード例 #16
0
 /**
  * Checks if 'xml generation' is enabled.
  *
  * @return <code>true</code> if 'xml generation' is enabled
  */
 public boolean getUpdateDefinition() {
   return ProtocolInvoker.getUpdateDefinition(_harvestRepository.getProtocol());
 }
コード例 #17
0
 /**
  * Enables/disables 'deep harvest'
  *
  * @param enabled <code>true</code> to enable 'deep harvest'
  */
 public void setUpdateContent(boolean enabled) {
   ProtocolInvoker.setUpdateContent(_harvestRepository.getProtocol(), enabled);
 }
コード例 #18
0
 /**
  * Sets host URL.
  *
  * @param hostUrl host URL
  */
 public void setHostUrl(String hostUrl) {
   _harvestRepository.setHostUrl(hostUrl);
 }
コード例 #19
0
 /**
  * Gets harvest frequency.
  *
  * @return harvest frequency
  */
 public String getHarvestFrequency() {
   return _harvestRepository.getHarvestFrequency().name().toLowerCase();
 }
コード例 #20
0
 /**
  * Gets SOAP URL.
  *
  * @return SOAP URL
  */
 public String getSoapUrl() {
   return _harvestRepository.getProtocol() instanceof ArcGISProtocol
       ? ((ArcGISProtocol) _harvestRepository.getProtocol()).getSoapUrl()
       : "";
 }
コード例 #21
0
 /**
  * Gets protocol name.
  *
  * @return protocol name
  */
 public String getType() {
   return _harvestRepository.getProtocol().getKind().toLowerCase();
 }
コード例 #22
0
  /**
   * Validates entered content.
   *
   * @param mb message broker
   * @return <code>true</code> if data is valid
   */
  public boolean validate(MessageBroker mb) {
    _valid = true;

    if (getHostUrl().length() == 0) {
      mb.addErrorMessage("catalog.harvest.manage.edit.err.hostUrlReq");
      _valid = false;
    }

    String kind = _harvestRepository.getProtocol().getKind();
    if (kind.equalsIgnoreCase(ProtocolType.ArcIms.name())) {
      if (getArcIms().getPortNoAsString().length() == 0) {
        mb.addErrorMessage("catalog.harvest.manage.edit.err.portNumberReq");
        _valid = false;
      } else {
        try {
          int portNo = Integer.parseInt(getArcIms().getPortNoAsString());
          if (!(portNo >= 0 && portNo < 65536)) {
            mb.addErrorMessage("catalog.harvest.manage.edit.err.portNumberInv");
            _valid = false;
          }
        } catch (NumberFormatException ex) {
          mb.addErrorMessage("catalog.harvest.manage.edit.err.portNumberInv");
          _valid = false;
        }
      }
      if (getArcIms().getServiceName().length() == 0) {
        mb.addErrorMessage("catalog.harvest.manage.edit.err.serviceNameReq");
        _valid = false;
      }
    } else if (kind.equalsIgnoreCase(ProtocolType.OAI.name())) {
      if (getOai().getPrefix().length() == 0) {
        mb.addErrorMessage("catalog.harvest.manage.edit.err.prefixReq");
        _valid = false;
      }
    } else if (kind.equalsIgnoreCase("arcgis")) {
      ArcGISProtocol p = (ArcGISProtocol) protocols.get("arcgis");
      if (p.getSoapUrl().length() == 0) {
        mb.addErrorMessage("catalog.harvest.manage.edit.err.soapUrl");
        _valid = false;
      }
    } else if (kind.equalsIgnoreCase("agp2agp")) {
      HarvestProtocolAgp2Agp p = (HarvestProtocolAgp2Agp) protocols.get("agp2agp");
      if (p != null) {
        if (!getArcgisDotComAllowed()) {
          if (p.getDestinationHost().toLowerCase().endsWith("arcgis.com")
              || p.getDestinationHost().toLowerCase().endsWith("arcgisonline.com")) {
            mb.addErrorMessage("catalog.harvest.manage.test.msg.agp2agp.arcgis.forbiden");
            _valid = false;
          }
        } else if (!getCrossAllowed()) {
          String srcHost[] = p.getSourceHost().split("[.]");
          String dstHost[] = p.getDestinationHost().split("[.]");

          if (srcHost != null && srcHost.length >= 2 && dstHost != null && dstHost.length >= 2) {
            if (srcHost[srcHost.length - 1].equalsIgnoreCase(dstHost[dstHost.length - 1])
                && srcHost[srcHost.length - 2].equalsIgnoreCase(dstHost[dstHost.length - 2])) {
              mb.addErrorMessage("catalog.harvest.manage.test.msg.agp2agp.cross.forbiden");
              _valid = false;
            }
          }
        }
        if (_valid) {
          if (!p.getSourceHost().matches(HOST_NAME_REGEX)) {
            mb.addErrorMessage("catalog.harvest.manage.edit.src.h.err");
            _valid = false;
          }
          if (p.getAttributeMap().getValue("src-q").isEmpty()) {
            mb.addErrorMessage("catalog.harvest.manage.edit.src.q.err");
            _valid = false;
          }
          if (p.getAttributeMap().getValue("src-m").isEmpty()) {
            mb.addErrorMessage("catalog.harvest.manage.edit.src.m.err");
            _valid = false;
          } else if (Val.chkLong(p.getAttributeMap().getValue("src-m"), 0) <= 0
              || Val.chkLong(p.getAttributeMap().getValue("src-m"), 0)
                  > HarvestProtocolAgp2Agp.getAgp2AgpMaxItems()) {
            mb.addErrorMessage(
                "catalog.harvest.manage.edit.src.m.err.less",
                new Object[] {HarvestProtocolAgp2Agp.getAgp2AgpMaxItems()});
            _valid = false;
          }
          if (p.getAttributeMap().getValue("src-u").isEmpty()) {
            mb.addErrorMessage("catalog.harvest.manage.edit.src.u.err");
            _valid = false;
          }
          if (p.getAttributeMap().getValue("src-p").isEmpty()) {
            mb.addErrorMessage("catalog.harvest.manage.edit.src.p.err");
            _valid = false;
          }

          if (!p.getDestinationHost().matches(HOST_NAME_REGEX)) {
            mb.addErrorMessage("catalog.harvest.manage.edit.dest.h.err");
            _valid = false;
          }
          if (p.getAttributeMap().getValue("dest-o").isEmpty()) {
            mb.addErrorMessage("catalog.harvest.manage.edit.dest.o.err");
            _valid = false;
          }
          if (p.getAttributeMap().getValue("dest-u").isEmpty()) {
            mb.addErrorMessage("catalog.harvest.manage.edit.dest.u.err");
            _valid = false;
          }
          if (p.getAttributeMap().getValue("dest-p").isEmpty()) {
            mb.addErrorMessage("catalog.harvest.manage.edit.dest.p.err");
            _valid = false;
          }
          if (p.getAttributeMap().getValue("dest-f").isEmpty()) {
            mb.addErrorMessage("catalog.harvest.manage.edit.dest.f.err");
            _valid = false;
          }
        }
      }
    }

    return _valid;
  }
コード例 #23
0
 /**
  * Sets owner id from string.
  *
  * @param value owner id
  */
 public void setOwnerId(String value) {
   _harvestRepository.setOwnerId(Val.chkInt(value, -1));
 }
コード例 #24
0
 /**
  * Gets time codes.
  *
  * @return time codes.
  */
 public String getTimeCodes() {
   return _harvestRepository.getProtocol().getAdHoc();
 }
コード例 #25
0
 /**
  * Sets sending notification switch flag.
  *
  * @param sendNotification sending notification switch flag
  */
 public void setSendNotification(String sendNotification) {
   _harvestRepository.setSendNotification(Val.chkBool(sendNotification, false));
 }
コード例 #26
0
 /**
  * Sets harvest frequency.
  *
  * @param harvestFrequency harvest frequency
  */
 public void setHarvestFrequency(String harvestFrequency) {
   _harvestRepository.setHarvestFrequency(
       HrRecord.HarvestFrequency.checkValueOf(harvestFrequency));
 }
コード例 #27
0
 /**
  * Sets protocol name.
  *
  * @param name protocol name name
  */
 public void setType(String name) {
   _harvestRepository.setProtocol(protocols.get(name));
 }
コード例 #28
0
 /**
  * Gets sending notification switch flag.
  *
  * @return sending notification switch flag
  */
 public String getSendNotification() {
   return Boolean.toString(_harvestRepository.getSendNotification());
 }
コード例 #29
0
 /**
  * Gets owner id as string.
  *
  * @return owner id
  */
 public String getOwnerId() {
   return Integer.toString(_harvestRepository.getOwnerId());
 }