<commit_before>/*
 * Copyright 2014 Esri, Inc..
 *
 * Licensed 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.georss.dcatdef;

import com.esri.gpt.control.georss.DcatField;
import com.esri.gpt.control.georss.DcatSchemas;
import com.esri.gpt.control.georss.IFeedAttribute;
import com.esri.gpt.control.georss.IFeedRecord;
import com.esri.gpt.framework.context.ApplicationConfiguration;
import com.esri.gpt.framework.context.ApplicationContext;
import com.esri.gpt.framework.util.Val;
import static com.esri.gpt.framework.util.Val.chkStr;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Properties;

/**
 * Record definition.
 */
public class DcatRecordDefinition {
  private static final ArrayList<DcatFieldDefinition> fieldDefinitions = new ArrayList<DcatFieldDefinition>();
  static {
    fieldDefinitions.add(new StringField("title",DcatFieldDefinition.OBLIGATORY){
      @Override
      protected String getDefaultValue(IFeedRecord r, Properties properties) {
        return chkStr(properties.getProperty(fldName),"?");
      }
    });
    fieldDefinitions.add(new StringField("description",DcatFieldDefinition.OBLIGATORY){
      @Override
      protected String getDefaultValue(IFeedRecord r, Properties properties) {
        return chkStr(properties.getProperty(fldName),"?");
      }
    });
    fieldDefinitions.add(new ArrayField ("keyword",DcatFieldDefinition.OBLIGATORY){
      @Override
      protected List<String> getDefaultValue(Properties properties) {
        List<String> list = Arrays.asList(chkStr(properties.getProperty(fldName)).replaceAll("^\\p{Space}*\\[|\\]\\p{Space}*$", "").split(","));
        for (int i=0; i<list.size(); i++) {
          list.set(i, list.get(i).replaceAll("^\\p{Space}*\\\"|\\\"\\p{Space}*$", ""));
        }
        return list;
      }
    });
    fieldDefinitions.add(new DateField  ("modified",DcatFieldDefinition.OBLIGATORY){

      @Override
      protected Date getDefaultValue(Properties properties) {
        String sDate = properties.getProperty(fldName);
        try {
          return ISODF.parseObject(sDate);
        } catch (ParseException ex) {
          return new Date();
        }
      }
      
    });
    fieldDefinitions.add(new PublisherField("publisher"));
    fieldDefinitions.add(new ContactPointField("contactPoint"));
    fieldDefinitions.add(new IdentifierField("identifier",DcatFieldDefinition.OBLIGATORY));
    fieldDefinitions.add(new StringField ("accessLevel",DcatFieldDefinition.OBLIGATORY){
      @Override
      protected String getDefaultValue(IFeedRecord r, Properties properties) {
        return chkStr(properties.getProperty(fldName),"public");
      }
    });
    fieldDefinitions.add(new StringField ("accrualPeriodicity"));
    fieldDefinitions.add(new ReferencesField("references","contentType"));
    fieldDefinitions.add(new StringField("accessLevelComment"){

      @Override
      protected String getOutFieldName() {
        return "rights";
      }

      @Override
      protected String getDefaultValue(IFeedRecord r, Properties properties) {
        return Val.chkStr(properties.getProperty("fldName"), "?");
      }

      @Override
      protected String readValue(DcatSchemas dcatSchemas, DcatField dcatField, IFeedRecord r, IFeedAttribute attr) {
        IFeedAttribute accessLevelAttribute = this.getFeedAttribute(dcatSchemas, r, "accessLevel");
        List<String> accessLevelList = accessLevelAttribute!=null? accessLevelAttribute.asList(): new ArrayList<String>();
        
        boolean nonPublic = false;
        for (String accessLevel: accessLevelList) {
          if (!"public".equals(accessLevel)) {
            nonPublic = true;
          }
        }
        
        if (nonPublic) {<commit_msg>DCAT1.1: Prints "rights" (accessLevelComment) only if record is not public.<commit_after>/*
 * Copyright 2014 Esri, Inc..
 *
 * Licensed 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.georss.dcatdef;

import com.esri.gpt.control.georss.DcatField;
import com.esri.gpt.control.georss.DcatSchemas;
import com.esri.gpt.control.georss.IFeedAttribute;
import com.esri.gpt.control.georss.IFeedRecord;
import com.esri.gpt.framework.context.ApplicationConfiguration;
import com.esri.gpt.framework.context.ApplicationContext;
import com.esri.gpt.framework.util.Val;
import static com.esri.gpt.framework.util.Val.chkStr;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * Record definition.
 */
public class DcatRecordDefinition {
  private static final ArrayList<DcatFieldDefinition> fieldDefinitions = new ArrayList<DcatFieldDefinition>();
  static {
    fieldDefinitions.add(new StringField("title",DcatFieldDefinition.OBLIGATORY){
      @Override
      protected String getDefaultValue(IFeedRecord r, Properties properties) {
        return chkStr(properties.getProperty(fldName),"?");
      }
    });
    fieldDefinitions.add(new StringField("description",DcatFieldDefinition.OBLIGATORY){
      @Override
      protected String getDefaultValue(IFeedRecord r, Properties properties) {
        return chkStr(properties.getProperty(fldName),"?");
      }
    });
    fieldDefinitions.add(new ArrayField ("keyword",DcatFieldDefinition.OBLIGATORY){
      @Override
      protected List<String> getDefaultValue(Properties properties) {
        List<String> list = Arrays.asList(chkStr(properties.getProperty(fldName)).replaceAll("^\\p{Space}*\\[|\\]\\p{Space}*$", "").split(","));
        for (int i=0; i<list.size(); i++) {
          list.set(i, list.get(i).replaceAll("^\\p{Space}*\\\"|\\\"\\p{Space}*$", ""));
        }
        return list;
      }
    });
    fieldDefinitions.add(new DateField  ("modified",DcatFieldDefinition.OBLIGATORY){

      @Override
      protected Date getDefaultValue(Properties properties) {
        String sDate = properties.getProperty(fldName);
        try {
          return ISODF.parseObject(sDate);
        } catch (ParseException ex) {
          return new Date();
        }
      }
      
    });
    fieldDefinitions.add(new PublisherField("publisher"));
    fieldDefinitions.add(new ContactPointField("contactPoint"));
    fieldDefinitions.add(new IdentifierField("identifier",DcatFieldDefinition.OBLIGATORY));
    fieldDefinitions.add(new StringField ("accessLevel",DcatFieldDefinition.OBLIGATORY){
      @Override
      protected String getDefaultValue(IFeedRecord r, Properties properties) {
        return chkStr(properties.getProperty(fldName),"public");
      }
    });
    fieldDefinitions.add(new StringField ("accrualPeriodicity"));
    fieldDefinitions.add(new ReferencesField("references","contentType"));
    fieldDefinitions.add(new StringField("accessLevelComment"){

      @Override
      protected String getOutFieldName() {
        return "rights";
      }

      @Override
      protected String getDefaultValue(IFeedRecord r, Properties properties) {
        return Val.chkStr(properties.getProperty("fldName"), "?");
      }

      @Override
      protected String readValue(DcatSchemas dcatSchemas, DcatField dcatField, IFeedRecord r, IFeedAttribute attr) {
        Map<String, IFeedAttribute> index = getIndex(r);
        if (index == null) {
          return null;
        }
        DcatField field = getAttributeField(dcatSchemas, index, r, "accessLevel");
        if (field == null) {
          return null;
        }
        IFeedAttribute accessLevelAttribute = getFeedAttribute(index, field);
    
        List<String> accessLevelList = accessLevelAttribute!=null? accessLevelAttribute.asList(): new ArrayList<String>();
        
        boolean nonPublic = false;
        for (String accessLevel: accessLevelList) {
          accessLevel = field.translate(accessLevel);
          if (!"public".equals(accessLevel)) {
            nonPublic = true;
            break;
          }
        }
        
        if (nonPublic) {
{'fraction_non_alphanumeric': 0.11447452568748667, 'fraction_numerical': 0.002131741632914091, 'mean_word_length': 3.622167487684729, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, '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': '6722800', 'n_tokens_mistral': 2671, 'n_tokens_neox': 2641, 'n_words': 579}