<commit_before>/*
 * Copyright 2003 - 2010 The eFaps Team
 *
 * 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.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.esjp.common.uitable;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;

import org.efaps.admin.datamodel.Attribute;
import org.efaps.admin.datamodel.Type;
import org.efaps.admin.event.Parameter;
import org.efaps.admin.event.Return;
import org.efaps.admin.event.Parameter.ParameterValues;
import org.efaps.admin.event.Return.ReturnValues;
import org.efaps.admin.program.esjp.EFapsRevision;
import org.efaps.admin.program.esjp.EFapsUUID;
import org.efaps.admin.ui.AbstractCommand;
import org.efaps.admin.ui.field.Field;
import org.efaps.db.Instance;
import org.efaps.db.SearchQuery;
import org.efaps.util.DateTimeUtil;
import org.efaps.util.EFapsException;
import org.joda.time.DateMidnight;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * TODO comment!
 *
 * @author The eFaps Team
 * @version $Id$
 */
@EFapsUUID("cbab3ae6-fe28-4604-838c-4c6d260156fb")
@EFapsRevision("$Rev$")
public class MultiPrint
{
    /**
     * Logger for this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(MultiPrint.class);

    /**
     * @param _parameter Parameter
     * @return Return with List of instances
     * @throws EFapsException on error
     */
    public Return execute(final Parameter _parameter)
        throws EFapsException
    {
        final Return ret = new Return();
        final Instance instance = _parameter.getInstance();
        final Map<?, ?> properties = (Map<?, ?>) _parameter.get(ParameterValues.PROPERTIES);

        final Map<?, ?> filter = (Map<?, ?>) _parameter.get(ParameterValues.OTHERS);

        final String types = (String) properties.get("Types");

        final boolean expandChildTypes = "true".equals(properties.get("ExpandChildTypes"));

        final String expand = (String) properties.get("Expand");
        final String alternateAttribute = (String) properties.get("AlternateAttribute");

        if (MultiPrint.LOG.isDebugEnabled()) {
            MultiPrint.LOG.debug("types=" + types);
        }

        final SearchQuery query = new SearchQuery();
        Type type = null;
        if (types != null) {
            query.setQueryTypes(types);
            query.setExpandChildTypes(expandChildTypes);
            type = Type.get(types);
        } else if (expand != null) {
            query.setExpand(instance, expand);
            type = Type.get(expand.substring(0, expand.indexOf("\\")));
        }

        final List<Instance> instances = getInstances(_parameter, filter, query, type);

        if (alternateAttribute != null) {
            final SearchQuery query2 = new SearchQuery();<commit_msg>- MulitPrint can now by used with more than one type at once.<commit_after>/*
 * Copyright 2003 - 2010 The eFaps Team
 *
 * 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.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.esjp.common.uitable;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;

import org.efaps.admin.datamodel.Attribute;
import org.efaps.admin.datamodel.Type;
import org.efaps.admin.event.Parameter;
import org.efaps.admin.event.Return;
import org.efaps.admin.event.Parameter.ParameterValues;
import org.efaps.admin.event.Return.ReturnValues;
import org.efaps.admin.program.esjp.EFapsRevision;
import org.efaps.admin.program.esjp.EFapsUUID;
import org.efaps.admin.ui.AbstractCommand;
import org.efaps.admin.ui.field.Field;
import org.efaps.db.Instance;
import org.efaps.db.SearchQuery;
import org.efaps.util.DateTimeUtil;
import org.efaps.util.EFapsException;
import org.joda.time.DateMidnight;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * TODO comment!
 *
 * @author The eFaps Team
 * @version $Id$
 */
@EFapsUUID("cbab3ae6-fe28-4604-838c-4c6d260156fb")
@EFapsRevision("$Rev$")
public class MultiPrint
{
    /**
     * Logger for this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(MultiPrint.class);

    /**
     * @param _parameter Parameter
     * @return Return with List of instances
     * @throws EFapsException on error
     */
    public Return execute(final Parameter _parameter)
        throws EFapsException
    {
        final Return ret = new Return();
        final Instance instance = _parameter.getInstance();
        final Map<?, ?> properties = (Map<?, ?>) _parameter.get(ParameterValues.PROPERTIES);

        final Map<?, ?> filter = (Map<?, ?>) _parameter.get(ParameterValues.OTHERS);

        final String types = (String) properties.get("Types");

        final boolean expandChildTypes = "true".equals(properties.get("ExpandChildTypes"));

        final String expand = (String) properties.get("Expand");
        final String alternateAttribute = (String) properties.get("AlternateAttribute");

        if (MultiPrint.LOG.isDebugEnabled()) {
            MultiPrint.LOG.debug("types=" + types);
        }

        final List<Instance> instances = new ArrayList<Instance>();
        SearchQuery query = new SearchQuery();
        Type type = null;
        if (types != null) {
            final String[] typesArray = types.split(";");
            for (int x = 0; x < typesArray.length; x++) {
                query = new SearchQuery();
                type = null;
                query.setQueryTypes(typesArray[x]);
                query.setExpandChildTypes(expandChildTypes);
                type = Type.get(typesArray[x]);

                instances.addAll(getInstances(_parameter, filter, query, type));
            }
        } else if (expand != null) {
            query.setExpand(instance, expand);
            type = Type.get(expand.substring(0, expand.indexOf("\\")));

            instances.addAll(getInstances(_parameter, filter, query, type));
        }

        if (alternateAttribute != null) {
            final SearchQuery query2 = new SearchQuery();
{'fraction_non_alphanumeric': 0.11548556430446194, 'fraction_numerical': 0.009807984528249759, 'mean_word_length': 3.1657077100115076, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, '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': '3750480', 'n_tokens_mistral': 2145, 'n_tokens_neox': 2061, 'n_words': 564}