<commit_before>package com.versionone.common.sdk;

import com.versionone.Oid;
import com.versionone.apiclient.APIException;
import com.versionone.apiclient.Asset;
import com.versionone.apiclient.IAttributeDefinition;
import com.versionone.apiclient.MetaException;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * This class represents one Task in the VersionOne system
 */
class Task {

    private static final String TASK_PREFIX = "Task.";

    public final Asset asset;
    private BigDecimal effort = BigDecimal.ZERO.setScale(2);
    private Map<String, IAttributeDefinition> definitions = new HashMap<String, IAttributeDefinition>(TasksProperties.values().length);

    /**
     * Create
     *
     * @param asset - Task asset
     */
    public Task(Asset asset) throws MetaException {
        this.asset = asset;
    }

    public String getToken() throws Exception {
        return asset.getOid().getToken();
    }

    /**
     * Get the value of an attribute
     *
     * @param key - name of attribute
     */
    private Object getValue(String key) {
        Object value = null;
        try {
            value = asset.getAttributes().get(TASK_PREFIX + key).getValue();
        } catch (Exception e) {
            //do nothing
        }
        return value;
    }

    public void setProperty(TasksProperties property, String value) {
        try {
            switch (property.type) {
                case LIST: {
                    final Oid oid = property.getValueOid(value);
                    if (oid != null && !TasksProperties.isEqual(getProperty(property), oid)) {
                        asset.setAttributeValue(getDefinition(property.propertyName), oid);
                    }
                    break;
                }
                case NUMBER: {
                    BigDecimal newValue = new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP);
                    if (newValue.signum() >= 0) {
                        if (property == TasksProperties.EFFORT) {
                            effort = newValue;
                        } else if (!TasksProperties.isEqual(getProperty(property), value)) {
                            asset.setAttributeValue(getDefinition(property.propertyName), value);
                        }
                    }
                    break;
                }
                default: {
                    if (!TasksProperties.isEqual(getProperty(property), value)) {
                        asset.setAttributeValue(getDefinition(property.propertyName), value);
                    }
                }
            }
        } catch (APIException e) {
            e.printStackTrace(); //do nothing
        } catch (MetaException e) {
            e.printStackTrace(); //do nothing
        } catch (NumberFormatException e) {
            e.printStackTrace(); //do nothing<commit_msg>fixed bug with very big numbers (now restriction on 1000000)<commit_after>package com.versionone.common.sdk;

import com.versionone.Oid;
import com.versionone.apiclient.APIException;
import com.versionone.apiclient.Asset;
import com.versionone.apiclient.IAttributeDefinition;
import com.versionone.apiclient.MetaException;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * This class represents one Task in the VersionOne system
 */
class Task {

    private static final String TASK_PREFIX = "Task.";

    public final Asset asset;
    private BigDecimal effort = BigDecimal.ZERO.setScale(2);
    private Map<String, IAttributeDefinition> definitions = new HashMap<String, IAttributeDefinition>(TasksProperties.values().length);
    private static final BigDecimal MAX_NUMBER_VALUE = BigDecimal.valueOf(1000000); 

    /**
     * Create
     *
     * @param asset - Task asset
     */
    public Task(Asset asset) throws MetaException {
        this.asset = asset;
    }

    public String getToken() throws Exception {
        return asset.getOid().getToken();
    }

    /**
     * Get the value of an attribute
     *
     * @param key - name of attribute
     */
    private Object getValue(String key) {
        Object value = null;
        try {
            value = asset.getAttributes().get(TASK_PREFIX + key).getValue();
        } catch (Exception e) {
            //do nothing
        }
        return value;
    }

    public void setProperty(TasksProperties property, String value) {
        try {
            switch (property.type) {
                case LIST: {
                    final Oid oid = property.getValueOid(value);
                    if (oid != null && !TasksProperties.isEqual(getProperty(property), oid)) {
                        asset.setAttributeValue(getDefinition(property.propertyName), oid);
                    }
                    break;
                }
                case NUMBER: {
                    BigDecimal newValue = new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP);
                    if (newValue.signum() >= 0 && newValue.compareTo(MAX_NUMBER_VALUE) <=0) {
                        if (property == TasksProperties.EFFORT) {
                            effort = newValue;
                        } else if (!TasksProperties.isEqual(getProperty(property), value)) {
                            asset.setAttributeValue(getDefinition(property.propertyName), value);
                        }
                    }
                    break;
                }
                default: {
                    if (!TasksProperties.isEqual(getProperty(property), value)) {
                        asset.setAttributeValue(getDefinition(property.propertyName), value);
                    }
                }
            }
        } catch (APIException e) {
            e.printStackTrace(); //do nothing
        } catch (MetaException e) {
            e.printStackTrace(); //do nothing
        } catch (NumberFormatException e) {
            e.printStackTrace(); //do nothing
{'fraction_non_alphanumeric': 0.09539805172992946, 'fraction_numerical': 0.003527040644944575, 'mean_word_length': 1.8076379066478077, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '962152', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1464, 'n_words': 350}