<commit_before>/*
 * Copyright 2009 Kantega AS
 *
 * 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 no.kantega.publishing.admin.content.behaviours.attributes;

import no.kantega.publishing.common.data.Content;
import no.kantega.publishing.common.data.attributes.Attribute;
import no.kantega.publishing.common.data.attributes.ListAttribute;
import no.kantega.publishing.common.data.attributes.DateAttribute;
import no.kantega.commons.exception.SystemException;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.DateFormat;

/**
 * User: <NAME>, Kantega AS
 * Date: May 19, 2009
 * Time: 4:05:43 PM
 */
public class PersistDateAttributeBehaviour implements PersistAttributeBehaviour {
    public void persistAttribute(Connection c, Content content, Attribute attribute) throws SQLException, SystemException {
        PreparedStatement st = c.prepareStatement("insert into contentattributes (ContentVersionId, AttributeType, DataType, Name, Value) values (?,?,?,?,?)");

        st.setInt(1, content.getVersionId());

        // Klassenavn angir navnet som brukes i databasen som attributttype
        String clsName = attribute.getClass().getName().toLowerCase();
        clsName = clsName.substring(clsName.lastIndexOf(".") + 1, clsName.lastIndexOf("attribute"));

        st.setString(2, clsName);
        st.setInt(3, attribute.getType());
        st.setString(4, attribute.getName());

        String value = attribute.getValue();
        if (attribute instanceof DateAttribute) {
            Date dateValue = ((DateAttribute)attribute).getValueAsDate();
            DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
            value = df.format(dateValue);
        }
        st.setString(5, value);

        st.execute();
    }
}<commit_msg>AP-687<commit_after>/*
 * Copyright 2009 Kantega AS
 *
 * 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 no.kantega.publishing.admin.content.behaviours.attributes;

import no.kantega.publishing.common.data.Content;
import no.kantega.publishing.common.data.attributes.Attribute;
import no.kantega.publishing.common.data.attributes.ListAttribute;
import no.kantega.publishing.common.data.attributes.DateAttribute;
import no.kantega.commons.exception.SystemException;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.DateFormat;

/**
 * User: <NAME>, Kantega AS
 * Date: May 19, 2009
 * Time: 4:05:43 PM
 */
public class PersistDateAttributeBehaviour implements PersistAttributeBehaviour {
    public void persistAttribute(Connection c, Content content, Attribute attribute) throws SQLException, SystemException {
        PreparedStatement st = c.prepareStatement("insert into contentattributes (ContentVersionId, AttributeType, DataType, Name, Value) values (?,?,?,?,?)");

        st.setInt(1, content.getVersionId());

        // Klassenavn angir navnet som brukes i databasen som attributttype
        String clsName = attribute.getClass().getName().toLowerCase();
        clsName = clsName.substring(clsName.lastIndexOf(".") + 1, clsName.lastIndexOf("attribute"));

        st.setString(2, clsName);
        st.setInt(3, attribute.getType());
        st.setString(4, attribute.getName());

        String value = attribute.getValue();
        if (attribute instanceof DateAttribute) {
            Date dateValue = ((DateAttribute)attribute).getValueAsDate();
            if (dateValue != null) {
                DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
                value = df.format(dateValue);
            } else {
                value = "";
            }
        }
        st.setString(5, value);

        st.execute();
    }
}
{'fraction_non_alphanumeric': 0.10581467022806657, 'fraction_numerical': 0.010889665091432094, 'mean_word_length': 3.6628352490421454, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6653679', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1318, 'n_words': 381}