<commit_before>/* See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * Esri Inc. licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.esri.gpt.control.harvest;

import com.esri.gpt.framework.adhoc.AdHocEventFactoryList;
import com.esri.gpt.framework.adhoc.AdHocEventList;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocol.ProtocolType;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolAgp2Agp;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolResource;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolArcIms;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolCsw;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolOai;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolWaf;
import com.esri.gpt.catalog.harvest.repository.HrRecord;
import com.esri.gpt.catalog.management.MmdEnums.ApprovalStatus;
import com.esri.gpt.control.webharvest.client.arcgis.ArcGISProtocol;
import com.esri.gpt.control.webharvest.protocol.Protocol;
import com.esri.gpt.control.webharvest.protocol.ProtocolFactory;
import com.esri.gpt.control.webharvest.protocol.ProtocolInvoker;
import com.esri.gpt.framework.collection.StringAttributeMap;
import com.esri.gpt.framework.context.ApplicationConfiguration;
import com.esri.gpt.framework.context.ApplicationContext;
import com.esri.gpt.framework.jsf.FacesMap;
import com.esri.gpt.framework.jsf.MessageBroker;
import com.esri.gpt.framework.util.Val;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import javax.faces.model.SelectItem;

/**
 * Provides harvest repository editing functionality.
 * It assures that each harvest repository can be viewed in the same, unified 
 * way regardless the protocol. It also provides smooth values translation
 * from/to native form as stored within the object and to/from string value as
 * required in most cases to display on the form.
 */
public class HarvestEditor {

// class variables =============================================================
/** CSW profiles manager */
private static CswProfilesManager _cswProfilesManager = new CswProfilesManager();
private static final String HOST_NAME_REGEX = "(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$)|(^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$)";

// instance variables ==========================================================
  
/** validation status */  
private boolean _valid;
  
/** Edited repository. */
private HrRecord _harvestRepository;

/** all possible protocols */
private TreeMap<String,Protocol> protocols = new TreeMap<String,Protocol>(String.CASE_INSENSITIVE_ORDER);
{
  ApplicationContext appCtx = ApplicationContext.getInstance();
  ApplicationConfiguration appCfg = appCtx.getConfiguration();
  for (Map.Entry<String,ProtocolFactory> e : appCfg.getProtocolFactories().entrySet()) {
    protocols.put(e.getKey(), e.getValue().newProtocol());
  }
}

private boolean arcgisDotComAllowed;
private boolean crossAllowed;

private FrequencyMode frequencyMode = FrequencyMode.PERIODICAL;

// constructors ================================================================
/**<commit_msg>Ability to use Agp2Agp harvest protocol with Portal for ArcGIS 10.2<commit_after>/* See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * Esri Inc. licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.esri.gpt.control.harvest;

import com.esri.gpt.catalog.harvest.protocols.HarvestProtocol.ProtocolType;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolAgp2Agp;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolResource;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolArcIms;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolCsw;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolOai;
import com.esri.gpt.catalog.harvest.protocols.HarvestProtocolWaf;
import com.esri.gpt.catalog.harvest.repository.HrRecord;
import com.esri.gpt.catalog.management.MmdEnums.ApprovalStatus;
import com.esri.gpt.control.webharvest.client.arcgis.ArcGISProtocol;
import com.esri.gpt.control.webharvest.protocol.Protocol;
import com.esri.gpt.control.webharvest.protocol.ProtocolFactory;
import com.esri.gpt.control.webharvest.protocol.ProtocolInvoker;
import com.esri.gpt.framework.collection.StringAttributeMap;
import com.esri.gpt.framework.context.ApplicationConfiguration;
import com.esri.gpt.framework.context.ApplicationContext;
import com.esri.gpt.framework.jsf.FacesMap;
import com.esri.gpt.framework.jsf.MessageBroker;
import com.esri.gpt.framework.util.Val;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import javax.faces.model.SelectItem;

/**
 * Provides harvest repository editing functionality.
 * It assures that each harvest repository can be viewed in the same, unified 
 * way regardless the protocol. It also provides smooth values translation
 * from/to native form as stored within the object and to/from string value as
 * required in most cases to display on the form.
 */
public class HarvestEditor {

// class variables =============================================================
/** CSW profiles manager */
private static CswProfilesManager _cswProfilesManager = new CswProfilesManager();
private static final String HOST_NAME_REGEX = "(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])([/].+)?$)|(^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])([/].+)?$)";

// instance variables ==========================================================
  
/** validation status */  
private boolean _valid;
  
/** Edited repository. */
private HrRecord _harvestRepository;

/** all possible protocols */
private TreeMap<String,Protocol> protocols = new TreeMap<String,Protocol>(String.CASE_INSENSITIVE_ORDER);
{
  ApplicationContext appCtx = ApplicationContext.getInstance();
  ApplicationConfiguration appCfg = appCtx.getConfiguration();
  for (Map.Entry<String,ProtocolFactory> e : appCfg.getProtocolFactories().entrySet()) {
    protocols.put(e.getKey(), e.getValue().newProtocol());
  }
}

private boolean arcgisDotComAllowed;
private boolean crossAllowed;

private FrequencyMode frequencyMode = FrequencyMode.PERIODICAL;

// constructors ================================================================
/**
{'fraction_non_alphanumeric': 0.16640625, 'fraction_numerical': 0.016145833333333335, 'mean_word_length': 5.411519198664441, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2368143', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2370, 'n_words': 536}