/**
   * 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 time codes.
  *
  * @param timeCodes time codes
  */
 public void setTimeCodes(String timeCodes) {
   _harvestRepository.getProtocol().setAdHoc(timeCodes);
 }
  /**
   * 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;
  }
 /**
  * Gets time codes.
  *
  * @return time codes.
  */
 public String getTimeCodes() {
   return _harvestRepository.getProtocol().getAdHoc();
 }
 /**
  * Gets SOAP URL.
  *
  * @return SOAP URL
  */
 public String getSoapUrl() {
   return _harvestRepository.getProtocol() instanceof ArcGISProtocol
       ? ((ArcGISProtocol) _harvestRepository.getProtocol()).getSoapUrl()
       : "";
 }
 /**
  * Sets SOAP URL.
  *
  * @param url SOAP URL
  */
 public void setSoapUrl(String url) {
   if (_harvestRepository.getProtocol() instanceof ArcGISProtocol) {
     ((ArcGISProtocol) _harvestRepository.getProtocol()).setSoapUrl(url);
   }
 }
 /**
  * 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());
 }
 /**
  * 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);
 }
 /**
  * Checks if 'auto-approve' is enabled.
  *
  * @return <code>true</code> if 'auto-approve' is enabled
  */
 public boolean getAutoApprove() {
   return ProtocolInvoker.getAutoApprove(_harvestRepository.getProtocol());
 }
Exemplo n.º 10
0
 /**
  * Enables/disables 'auto-approve'
  *
  * @param enabled <code>true</code> to enable 'auto-approve'
  */
 public void setAutoApprove(boolean enabled) {
   ProtocolInvoker.setAutoApprove(_harvestRepository.getProtocol(), enabled);
 }
Exemplo n.º 11
0
 /**
  * Enables/disables 'xml generation'
  *
  * @param enabled <code>true</code> to enable 'xml generation'
  */
 public void setUpdateDefinition(boolean enabled) {
   ProtocolInvoker.setUpdateDefinition(_harvestRepository.getProtocol(), enabled);
 }
Exemplo n.º 12
0
 /**
  * Checks if 'xml generation' is enabled.
  *
  * @return <code>true</code> if 'xml generation' is enabled
  */
 public boolean getUpdateDefinition() {
   return ProtocolInvoker.getUpdateDefinition(_harvestRepository.getProtocol());
 }
Exemplo n.º 13
0
 /**
  * Enables/disables 'deep harvest'
  *
  * @param enabled <code>true</code> to enable 'deep harvest'
  */
 public void setUpdateContent(boolean enabled) {
   ProtocolInvoker.setUpdateContent(_harvestRepository.getProtocol(), enabled);
 }
Exemplo n.º 14
0
 /**
  * Checks if 'deep harvest' is enabled.
  *
  * @return <code>true</code> if 'deep harvest' is enabled
  */
 public boolean getUpdateContent() {
   return ProtocolInvoker.getUpdateContent(_harvestRepository.getProtocol());
 }
Exemplo n.º 15
0
 /**
  * Gets protocol name.
  *
  * @return protocol name
  */
 public String getType() {
   return _harvestRepository.getProtocol().getKind().toLowerCase();
 }