<commit_before>/*
 * Copyright (c) 2016, Mirante and/or its affiliates. All rights reserved.
 * Mirante PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package br.net.mirante.singular.form.service;

import br.net.mirante.singular.form.SInstance;
import br.net.mirante.singular.form.SingularFormException;
import br.net.mirante.singular.form.document.RefType;
import br.net.mirante.singular.form.document.SDocumentFactory;
import br.net.mirante.singular.form.internal.xml.MElement;
import br.net.mirante.singular.form.io.MformPersistenciaXML;
import br.net.mirante.singular.form.persistence.FormKey;
import br.net.mirante.singular.form.persistence.FormKeyLong;
import br.net.mirante.singular.form.persistence.SPackageFormPersistence;
import br.net.mirante.singular.form.persistence.dao.FormDAO;
import br.net.mirante.singular.form.persistence.entity.FormEntity;
import br.net.mirante.singular.form.type.core.annotation.AtrAnnotation;

import javax.inject.Inject;
import javax.transaction.Transactional;

@Transactional
public class FormService implements IFormService{

    @Inject
    private FormDAO formDAO;

    public FormKey keyFromObject(Object objectValueToBeConverted) {
        return FormKeyLong.convertToKey(objectValueToBeConverted);
    }

    @Override
    public SInstance loadFormInstance(FormKey key, RefType refType, SDocumentFactory documentFactory) {
        FormEntity entity = formDAO.find(getCod(key));
        if(entity == null){
            return null;
        }
        SInstance instance = MformPersistenciaXML.fromXML(refType, entity.getXml(), documentFactory);
        
        MformPersistenciaXML.annotationLoadFromXml(instance, entity.getXmlAnnotations());
        
        return instance;
    }
    
    @Override
    public FormKey insertOrUpdate(SInstance instance) {
        FormKey key = getKey(instance);
        if (key == null) {
            key = insert(instance);
        } else {
            update(instance);
        }
        return key;
    }<commit_msg>[FORM-SERVICE] Correção de bug: não gravava corretamente o atributo FormKey na SInstance<commit_after>/*
 * Copyright (c) 2016, Mirante and/or its affiliates. All rights reserved.
 * Mirante PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package br.net.mirante.singular.form.service;

import br.net.mirante.singular.form.SInstance;
import br.net.mirante.singular.form.SingularFormException;
import br.net.mirante.singular.form.document.RefType;
import br.net.mirante.singular.form.document.SDocumentFactory;
import br.net.mirante.singular.form.internal.xml.MElement;
import br.net.mirante.singular.form.io.MformPersistenciaXML;
import br.net.mirante.singular.form.persistence.FormKey;
import br.net.mirante.singular.form.persistence.FormKeyLong;
import br.net.mirante.singular.form.persistence.SPackageFormPersistence;
import br.net.mirante.singular.form.persistence.dao.FormDAO;
import br.net.mirante.singular.form.persistence.entity.FormEntity;
import br.net.mirante.singular.form.type.core.annotation.AtrAnnotation;

import javax.inject.Inject;
import javax.transaction.Transactional;

@Transactional
public class FormService implements IFormService{

    @Inject
    private FormDAO formDAO;

    public FormKey keyFromObject(Object objectValueToBeConverted) {
        return FormKeyLong.convertToKey(objectValueToBeConverted);
    }

    @Override
    public SInstance loadFormInstance(FormKey key, RefType refType, SDocumentFactory documentFactory) {
        FormEntity entity = formDAO.find(getCod(key));
        if(entity == null){
            return null;
        }
        SInstance instance = MformPersistenciaXML.fromXML(refType, entity.getXml(), documentFactory);
        
        MformPersistenciaXML.annotationLoadFromXml(instance, entity.getXmlAnnotations());

        instance.setAttributeValue(SPackageFormPersistence.ATR_FORM_KEY, key);
        return instance;
    }
    
    @Override
    public FormKey insertOrUpdate(SInstance instance) {
        FormKey key = getKey(instance);
        if (key == null) {
            key = insert(instance);
            instance.setAttributeValue(SPackageFormPersistence.ATR_FORM_KEY, key);
        } else {
            update(instance);
        }
        return key;
    }
{'fraction_non_alphanumeric': 0.09476894205958246, 'fraction_numerical': 0.0018766127140511376, 'mean_word_length': 3.796400449943757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '379311', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1250, 'n_words': 229}