<commit_before>/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package org.opencps.dossiermgt.service.impl;

import java.util.Date;
import java.util.List;

import org.opencps.dossiermgt.NoSuchDossierPartException;
import org.opencps.dossiermgt.comparator.DossierPartSiblingComparator;
import org.opencps.dossiermgt.model.DossierPart;
import org.opencps.dossiermgt.service.base.DossierPartLocalServiceBaseImpl;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.service.ServiceContext;

/**
 * The implementation of the dossier part local service. <p> All custom service
 * methods should be put in this class. Whenever methods are added, rerun
 * ServiceBuilder to copy their definitions into the
 * {@link org.opencps.dossiermgt.service.DossierPartLocalService} interface. <p>
 * This is a local service. Methods of this service will not have security
 * checks based on the propagated JAAS credentials because this service can only
 * be accessed from within the same VM. </p>
 *
 * @author trungnt
 * @see org.opencps.dossiermgt.service.base.DossierPartLocalServiceBaseImpl
 * @see org.opencps.dossiermgt.service.DossierPartLocalServiceUtil
 */
public class DossierPartLocalServiceImpl
	extends DossierPartLocalServiceBaseImpl {

	public DossierPart addDossierPart(
		long dossierTemplateId, String partNo, String partName, String partTip,
		int partType, long parentId, double sibling, String formScript,
		String formReport, String sampleData, boolean required,
		String templateFileNo, long userId, ServiceContext serviceContext)
		throws SystemException, NoSuchDossierPartException {

		long dossierPartId =
			CounterLocalServiceUtil.increment(DossierPart.class.getName());
		DossierPart dossierPart = dossierPartPersistence.create(dossierPartId);

		String treeIndex = getTreeIndex(sibling,parentId);

		Date currentDate = new Date();

		dossierPart.setUserId(userId);
		dossierPart.setCompanyId(serviceContext.getCompanyId());
		dossierPart.setGroupId(serviceContext.getScopeGroupId());
		dossierPart.setCreateDate(currentDate);
		dossierPart.setModifiedDate(currentDate);

		dossierPart.setDossierTemplateId(dossierTemplateId);
		dossierPart.setPartNo(partNo);
		dossierPart.setPartName(partName);
		dossierPart.setPartTip(partTip);
		dossierPart.setPartType(partType);
		dossierPart.setParentId(parentId);
		dossierPart.setSibling(sibling);
		dossierPart.setFormScript(formScript);
		dossierPart.setFormReport(formReport);
		dossierPart.setSampleData(sampleData);
		dossierPart.setRequired(required);
		dossierPart.setTemplateFileNo(templateFileNo);
		dossierPart.setTreeIndex(treeIndex);

		return dossierPartPersistence.update(dossierPart);
	}

	public DossierPart updateDossierPart(
		long dossierPartId, long dossierTemplateId, String partNo,
		String partName, String partTip, int partType, long parentId,
		double sibling, String formScript, String formReport,
		String sampleData, boolean required, String templateFileNo,

		long userId,boolean hasSign, ServiceContext serviceContext)
		throws SystemException, NoSuchDossierPartException {

		DossierPart dossierPartBeforeUpdateSibling =
			dossierPartPersistence.fetchByPrimaryKey(dossierPartId);
		
		double siblingBefore = dossierPartBeforeUpdateSibling.getSibling();
		if(siblingBefore != sibling) {
			DossierPart dossierPartSwapPosition = dossierPartPersistence
					.findByT_S(dossierTemplateId, sibling);
			String treeIndex = getTreeIndex(siblingBefore,
					dossierPartSwapPosition.getParentId());
			
			dossierPartSwapPosition.setSibling(siblingBefore);
			dossierPartSwapPosition.setTreeIndex(treeIndex);
			dossierPartPersistence.update(dossierPartSwapPosition);
			updateTreeIndexChirls(dossierPartSwapPosition.getDossierpartId());
			
			//update this dossierpart sibling
			String thisTreeIndex = getTreeIndex(sibling,
					dossierPartBeforeUpdateSibling.getParentId());
			
			dossierPartBeforeUpdateSibling.setSibling(sibling);
			dossierPartBeforeUpdateSibling.setTreeIndex(thisTreeIndex);
			dossierPartPersistence.update(dossierPartBeforeUpdateSibling);
			updateTreeIndexChirls(dossierPartBeforeUpdateSibling.getDossierpartId());
			
		}
		DossierPart dossierPart =
				dossierPartPersistence.fetchByPrimaryKey(dossierPartId);
		Date currentDate = new Date();

		dossierPart.setUserId(userId);
		dossierPart.setCompanyId(serviceContext.getCompanyId());
		dossierPart.setGroupId(serviceContext.getScopeGroupId());
		dossierPart.setCreateDate(currentDate);
		dossierPart.setModifiedDate(currentDate);

		dossierPart.setDossierTemplateId(dossierTemplateId);
		dossierPart.setPartName(partName);
		dossierPart.setPartNo(partNo);
		dossierPart.setPartTip(partTip);
		dossierPart.setPartType(partType);
		dossierPart.setParentId(parentId);
		dossierPart.setFormScript(formScript);
		dossierPart.setFormReport(formReport);
		dossierPart.setSampleData(sampleData);
		dossierPart.setRequired(required);
		dossierPart.setTemplateFileNo(templateFileNo);

		return dossierPartPersistence.update(dossierPart);<commit_msg>Update DossierPartLocalService <commit_after>/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package org.opencps.dossiermgt.service.impl;

import java.util.Date;
import java.util.List;

import org.opencps.dossiermgt.NoSuchDossierPartException;
import org.opencps.dossiermgt.comparator.DossierPartSiblingComparator;
import org.opencps.dossiermgt.model.DossierPart;
import org.opencps.dossiermgt.service.base.DossierPartLocalServiceBaseImpl;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.service.ServiceContext;

/**
 * The implementation of the dossier part local service. <p> All custom service
 * methods should be put in this class. Whenever methods are added, rerun
 * ServiceBuilder to copy their definitions into the
 * {@link org.opencps.dossiermgt.service.DossierPartLocalService} interface. <p>
 * This is a local service. Methods of this service will not have security
 * checks based on the propagated JAAS credentials because this service can only
 * be accessed from within the same VM. </p>
 *
 * @author trungnt
 * @see org.opencps.dossiermgt.service.base.DossierPartLocalServiceBaseImpl
 * @see org.opencps.dossiermgt.service.DossierPartLocalServiceUtil
 */
public class DossierPartLocalServiceImpl
	extends DossierPartLocalServiceBaseImpl {

	public DossierPart addDossierPart(
		long dossierTemplateId, String partNo, String partName, String partTip,
		int partType, long parentId, double sibling, String formScript,
		String formReport, String sampleData, boolean required,
		String templateFileNo, long userId, boolean hasSign, ServiceContext serviceContext)
		throws SystemException, NoSuchDossierPartException {

		long dossierPartId =
			CounterLocalServiceUtil.increment(DossierPart.class.getName());
		DossierPart dossierPart = dossierPartPersistence.create(dossierPartId);

		String treeIndex = getTreeIndex(sibling,parentId);

		Date currentDate = new Date();

		dossierPart.setUserId(userId);
		dossierPart.setCompanyId(serviceContext.getCompanyId());
		dossierPart.setGroupId(serviceContext.getScopeGroupId());
		dossierPart.setCreateDate(currentDate);
		dossierPart.setModifiedDate(currentDate);

		dossierPart.setDossierTemplateId(dossierTemplateId);
		dossierPart.setPartNo(partNo);
		dossierPart.setPartName(partName);
		dossierPart.setPartTip(partTip);
		dossierPart.setPartType(partType);
		dossierPart.setParentId(parentId);
		dossierPart.setSibling(sibling);
		dossierPart.setFormScript(formScript);
		dossierPart.setFormReport(formReport);
		dossierPart.setSampleData(sampleData);
		dossierPart.setRequired(required);
		dossierPart.setTemplateFileNo(templateFileNo);
		dossierPart.setTreeIndex(treeIndex);
		dossierPart.setHasSign(hasSign);
		
		return dossierPartPersistence.update(dossierPart);
	}

	public DossierPart updateDossierPart(
		long dossierPartId, long dossierTemplateId, String partNo,
		String partName, String partTip, int partType, long parentId,
		double sibling, String formScript, String formReport,
		String sampleData, boolean required, String templateFileNo,

		long userId,boolean hasSign, ServiceContext serviceContext)
		throws SystemException, NoSuchDossierPartException {

		DossierPart dossierPartBeforeUpdateSibling =
			dossierPartPersistence.fetchByPrimaryKey(dossierPartId);
		
		double siblingBefore = dossierPartBeforeUpdateSibling.getSibling();
		if(siblingBefore != sibling) {
			DossierPart dossierPartSwapPosition = dossierPartPersistence
					.findByT_S(dossierTemplateId, sibling);
			String treeIndex = getTreeIndex(siblingBefore,
					dossierPartSwapPosition.getParentId());
			
			dossierPartSwapPosition.setSibling(siblingBefore);
			dossierPartSwapPosition.setTreeIndex(treeIndex);
			dossierPartPersistence.update(dossierPartSwapPosition);
			updateTreeIndexChirls(dossierPartSwapPosition.getDossierpartId());
			
			//update this dossierpart sibling
			String thisTreeIndex = getTreeIndex(sibling,
					dossierPartBeforeUpdateSibling.getParentId());
			
			dossierPartBeforeUpdateSibling.setSibling(sibling);
			dossierPartBeforeUpdateSibling.setTreeIndex(thisTreeIndex);
			dossierPartPersistence.update(dossierPartBeforeUpdateSibling);
			updateTreeIndexChirls(dossierPartBeforeUpdateSibling.getDossierpartId());
			
		}
		DossierPart dossierPart =
				dossierPartPersistence.fetchByPrimaryKey(dossierPartId);
		Date currentDate = new Date();

		dossierPart.setUserId(userId);
		dossierPart.setCompanyId(serviceContext.getCompanyId());
		dossierPart.setGroupId(serviceContext.getScopeGroupId());
		dossierPart.setCreateDate(currentDate);
		dossierPart.setModifiedDate(currentDate);

		dossierPart.setDossierTemplateId(dossierTemplateId);
		dossierPart.setPartName(partName);
		dossierPart.setPartNo(partNo);
		dossierPart.setPartTip(partTip);
		dossierPart.setPartType(partType);
		dossierPart.setParentId(parentId);
		dossierPart.setFormScript(formScript);
		dossierPart.setFormReport(formReport);
		dossierPart.setSampleData(sampleData);
		dossierPart.setRequired(required);
		dossierPart.setTemplateFileNo(templateFileNo);
		dossierPart.setHasSign(hasSign);
		
		return dossierPartPersistence.update(dossierPart);
{'fraction_non_alphanumeric': 0.07851274667570085, 'fraction_numerical': 0.0010163462352841535, 'mean_word_length': 6.393863494051346, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6822352', 'n_tokens_mistral': 3901, 'n_tokens_neox': 3515, 'n_words': 723}