<commit_before>/* Copyright 2005 I Serv Consultoria Empresarial Ltda.
 *
 * 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 org.helianto.core.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.helianto.core.Programmable;
import org.helianto.core.base.AbstractHumanReadable;
import org.helianto.core.def.CategoryGroup;
import org.helianto.core.domain.type.TrunkEntity;

/**
 * Categories.  
 * 
 * @author <NAME>
 */
@javax.persistence.Entity
@Table(name="core_category",
    uniqueConstraints = {@UniqueConstraint(columnNames={"entityId", "categoryGroup", "categoryCode"})}
)
public class Category 
	extends AbstractHumanReadable
	implements 
	  TrunkEntity
	, Programmable

{

    private static final long serialVersionUID = 1L;
    private int id;
    private Entity entity;
    private char categoryGroup;
    private String categoryCode;
    private String categoryLabel;
    private String categoryName;
    private char priority;
    private String scriptItems;

    /** 
     * Default constructor
     */
    public Category() {
    	super();
    	setCategoryGroupAsEnum(CategoryGroup.NOT_DEFINED);
    	setCategoryCode("");
    	setCategoryLabel("");
    	setCategoryName("");
    	setPriority('0');
    }
    
    /** 
     * Key constructor
     * 
     * @param entity
     * @param categoryGroup
     * @param categoryCode
     */
    public  Category(Entity entity, CategoryGroup categoryGroup, String categoryCode) {
    	this();
    	setEntity(entity);
        setCategoryGroupAsEnum(categoryGroup);
        setCategoryCode(categoryCode);
    }

    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    public int getId() {
        return this.id;
    }
    public void setId(int id) {
        this.id = id;
    }

    /**
     * Category entity.
     */
    @ManyToOne
    @JoinColumn(name="entityId")
    public Entity getEntity() {
        return this.entity;
    }
    public void setEntity(Entity entity) {
        this.entity = entity;
    }

    /**
     * Group of categories.
     */
	public char getCategoryGroup() {
		return categoryGroup;
	}
	public void setCategoryGroup(char categoryGroup) {
		this.categoryGroup = categoryGroup;
	}
	public void setCategoryGroupAsEnum(CategoryGroup categoryGroup) {
		this.categoryGroup = categoryGroup.getValue();
	}

    /**
     * Category code.
     */
    @Column(length=20)
    public String getCategoryCode() {
        return this.categoryCode;
    }
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    
    /**
     * Category label.
     */
    @Column(length=32)
    public String getCategoryLabel() {
		return categoryLabel;
	}
    public void setCategoryLabel(String categoryLabel) {
		this.categoryLabel = categoryLabel;
	}

    /**
     * Category name.
     */
    @Column(length=64)
    public String getCategoryName() {
        return this.categoryName;
    }
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    /**
     * Priority.
     */
	public char getPriority() {
		return priority;
	}
	public void setPriority(char priority) {
		this.priority = priority;
	}

    /**
     * Key-value pair list of scripts, separated by comma.
     */
    @Column(length=255)
    public String getScriptItems() {
		return scriptItems;
	}
    public void setScriptItems(String scriptItems) {
		this.scriptItems = scriptItems;
	}
    
    /**
     * <<Transient>> Key-value pair list of scripts converted to array.
     */
    @Transient
    public String[] getScriptItemsAsArray() {
		if (getScriptItems()!=null && getScriptItems().trim().length()>0) {
			return getScriptItems().replace(" ", "").split(",");
		}
		return new String[] {};
	}
	public void setScriptItemsAsArray(String[] scriptItemsArray) {
		setScriptItems(scriptItemsArray.toString().replace("[", "").replace("]", ""));
	}
	
	/*
	 * Transient field to hold actual script list.
	 */
	private List<String> scriptList = new ArrayList<String>();
    
    /**
     * <<Transient>> Script list, likely to be loaded at runtime.
     */
    @Transient
    public List<String> getScriptList() {
    	return scriptList;
    }
    public void setScriptList(List<String> scriptList) {
		this.scriptList = scriptList;
	}
    
    /**
     * Adiciona contedo de um script  lista.
     * 
     * @param scriptContent
     */
    public void addScriptContent(String scriptContent) {
    	getScriptList().add(scriptContent);
	}

    /**
     * toString
     * @return String
     */<commit_msg>Added properties to categories.<commit_after>/* Copyright 2005 I Serv Consultoria Empresarial Ltda.
 *
 * 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 org.helianto.core.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.helianto.core.Programmable;
import org.helianto.core.base.AbstractHumanReadable;
import org.helianto.core.def.CategoryGroup;
import org.helianto.core.domain.type.TrunkEntity;
import org.helianto.core.utils.StringListUtils;

/**
 * Categories.  
 * 
 * @author <NAME>
 */
@javax.persistence.Entity
@Table(name="core_category",
    uniqueConstraints = {@UniqueConstraint(columnNames={"entityId", "categoryGroup", "categoryCode"})}
)
public class Category 
	extends AbstractHumanReadable
	implements 
	  TrunkEntity
	, Programmable

{

    private static final long serialVersionUID = 1L;
    private int id;
    private Entity entity;
    private char categoryGroup;
    private String categoryCode;
    private String categoryLabel;
    private String categoryName;
    private char priority;
    private String scriptItems;
    private String properties;

    /** 
     * Default constructor
     */
    public Category() {
    	super();
    	setCategoryGroupAsEnum(CategoryGroup.NOT_DEFINED);
    	setCategoryCode("");
    	setCategoryLabel("");
    	setCategoryName("");
    	setPriority('0');
    }
    
    /** 
     * Key constructor
     * 
     * @param entity
     * @param categoryGroup
     * @param categoryCode
     */
    public  Category(Entity entity, CategoryGroup categoryGroup, String categoryCode) {
    	this();
    	setEntity(entity);
        setCategoryGroupAsEnum(categoryGroup);
        setCategoryCode(categoryCode);
    }

    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    public int getId() {
        return this.id;
    }
    public void setId(int id) {
        this.id = id;
    }

    /**
     * Category entity.
     */
    @ManyToOne
    @JoinColumn(name="entityId")
    public Entity getEntity() {
        return this.entity;
    }
    public void setEntity(Entity entity) {
        this.entity = entity;
    }

    /**
     * Group of categories.
     */
	public char getCategoryGroup() {
		return categoryGroup;
	}
	public void setCategoryGroup(char categoryGroup) {
		this.categoryGroup = categoryGroup;
	}
	public void setCategoryGroupAsEnum(CategoryGroup categoryGroup) {
		this.categoryGroup = categoryGroup.getValue();
	}

    /**
     * Category code.
     */
    @Column(length=20)
    public String getCategoryCode() {
        return this.categoryCode;
    }
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    
    /**
     * Category label.
     */
    @Column(length=32)
    public String getCategoryLabel() {
		return categoryLabel;
	}
    public void setCategoryLabel(String categoryLabel) {
		this.categoryLabel = categoryLabel;
	}

    /**
     * Category name.
     */
    @Column(length=64)
    public String getCategoryName() {
        return this.categoryName;
    }
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    /**
     * Priority.
     */
	public char getPriority() {
		return priority;
	}
	public void setPriority(char priority) {
		this.priority = priority;
	}

    /**
     * Key-value pair list of scripts, separated by comma.
     */
    @Column(length=255)
    public String getScriptItems() {
		return scriptItems;
	}
    public void setScriptItems(String scriptItems) {
		this.scriptItems = scriptItems;
	}
    
    /**
     * <<Transient>> Key-value pair list of scripts converted to array.
     */
    @Transient
    public String[] getScriptItemsAsArray() {
    	return StringListUtils.stringToArray(getScriptItems());
	}
	public void setScriptItemsAsArray(String[] scriptItemsArray) {
		setScriptItems(StringListUtils.arrayToString(scriptItemsArray));
	}
	
	/*
	 * Transient field to hold actual script list.
	 */
	private List<String> scriptList = new ArrayList<String>();
    
    /**
     * <<Transient>> Script list, likely to be loaded at runtime.
     */
    @Transient
    public List<String> getScriptList() {
    	return scriptList;
    }
    public void setScriptList(List<String> scriptList) {
		this.scriptList = scriptList;
	}
    
    /**
     * Adiciona contedo de um script  lista.
     * 
     * @param scriptContent
     */
    public void addScriptContent(String scriptContent) {
    	getScriptList().add(scriptContent);
	}

	/**
	 * Custom properties.
	 */
	@Column(length=128)
	public String getProperties() {
		return properties;
	}
	public void setProperties(String properties) {
		this.properties = properties;
	}
	
    /**
     * <<Transient>> Key-value pair list of properties converted to array.
     */
    @Transient
    public String[] getPropertiesAsArray() {
    	return StringListUtils.stringToArray(getProperties());
	}
	public void setPropertiesAsArray(String[] propertiesArray) {
		setProperties(StringListUtils.arrayToString(propertiesArray));
	}
	
    /**
     * toString
     * @return String
     */
{'fraction_non_alphanumeric': 0.10215623895369388, 'fraction_numerical': 0.003711558854718982, 'mean_word_length': 3.0885115606936417, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, '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': '937910', 'n_tokens_mistral': 3279, 'n_tokens_neox': 3192, 'n_words': 820}