<commit_before>/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * The Original Code is OpenELIS code.
 *
 * Copyright (C) ITECH, University of Washington, Seattle WA.  All Rights Reserved.
 */

package us.mn.state.health.lims.testconfiguration.action;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import us.mn.state.health.lims.common.action.BaseAction;
import us.mn.state.health.lims.common.services.TestService;
import us.mn.state.health.lims.hibernate.HibernateUtil;
import us.mn.state.health.lims.test.dao.TestDAO;
import us.mn.state.health.lims.test.daoimpl.TestDAOImpl;
import us.mn.state.health.lims.test.valueholder.Test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;


public class TestOrderabilityUpdate extends BaseAction {

    @Override
    protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

        String changeList = ((DynaValidatorForm) form).getString("jsonChangeList");

        JSONParser parser=new JSONParser();

        JSONObject obj = (JSONObject)parser.parse(changeList);

        List<String> orderableTestIds = getIdsForActions("activateTest", obj, parser);
        List<String> unorderableTestIds = getIdsForActions("deactivateTest", obj, parser);

        List<Test> tests = getTests(unorderableTestIds, false);
        tests.addAll(getTests(orderableTestIds, true));

        Transaction tx = HibernateUtil.getSession().beginTransaction();

        TestDAO testDAO = new TestDAOImpl();

        try{
            for(Test test : tests){
                testDAO.updateData(test);
            }

            tx.commit();
        }catch( HibernateException e ){
            tx.rollback();
        }finally{
            HibernateUtil.closeSession();
        }

        return mapping.findForward(FWD_SUCCESS);
    }<commit_msg>Bug fix for setting orderable/not orderable<commit_after>/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * The Original Code is OpenELIS code.
 *
 * Copyright (C) ITECH, University of Washington, Seattle WA.  All Rights Reserved.
 */

package us.mn.state.health.lims.testconfiguration.action;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import us.mn.state.health.lims.common.action.BaseAction;
import us.mn.state.health.lims.common.services.TestService;
import us.mn.state.health.lims.hibernate.HibernateUtil;
import us.mn.state.health.lims.test.dao.TestDAO;
import us.mn.state.health.lims.test.daoimpl.TestDAOImpl;
import us.mn.state.health.lims.test.valueholder.Test;
import us.mn.state.health.lims.typeofsample.util.TypeOfSampleUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;


public class TestOrderabilityUpdate extends BaseAction {

    @Override
    protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

        String changeList = ((DynaValidatorForm) form).getString("jsonChangeList");

        JSONParser parser=new JSONParser();

        JSONObject obj = (JSONObject)parser.parse(changeList);

        List<String> orderableTestIds = getIdsForActions("activateTest", obj, parser);
        List<String> unorderableTestIds = getIdsForActions("deactivateTest", obj, parser);

        List<Test> tests = getTests(unorderableTestIds, false);
        tests.addAll(getTests(orderableTestIds, true));

        Transaction tx = HibernateUtil.getSession().beginTransaction();

        TestDAO testDAO = new TestDAOImpl();

        try{
            for(Test test : tests){
                testDAO.updateData(test);
            }

            tx.commit();
        }catch( HibernateException e ){
            tx.rollback();
        }finally{
            HibernateUtil.closeSession();
        }

        TypeOfSampleUtil.clearCache();
        return mapping.findForward(FWD_SUCCESS);
    }
{'fraction_non_alphanumeric': 0.09680252986647928, 'fraction_numerical': 0.0007027406886858749, 'mean_word_length': 3.865811965811966, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6820167', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1563, 'n_words': 404}