<commit_before>package edu.arizona.kfs.module.cam.document.validation.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.kuali.kfs.module.cam.businessobject.AssetGlobal;
import org.kuali.kfs.module.cam.businessobject.AssetGlobalDetail;
import org.kuali.kfs.sys.KFSConstants;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.rice.kns.document.MaintenanceDocument;
import org.kuali.rice.krad.service.BusinessObjectService;
import org.kuali.rice.krad.util.GlobalVariables;
import org.kuali.rice.krad.util.ObjectUtils;

import edu.arizona.kfs.module.cam.CamsConstants;
import edu.arizona.kfs.module.cam.CamsKeyConstants;
import edu.arizona.kfs.module.cam.CamsPropertyConstants;
import edu.arizona.kfs.module.cam.businessobject.AssetGlobalDetailExtension;
import edu.arizona.kfs.module.cam.businessobject.AssetInventoryUnit;
import edu.arizona.kfs.sys.KFSPropertyConstants;

public class AssetGlobalRule extends org.kuali.kfs.module.cam.document.validation.impl.AssetGlobalRule {

	@Override
	protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
		boolean success = true;
		success &= super.processCustomSaveDocumentBusinessRules(document);

		AssetGlobal assetGlobal = (AssetGlobal) document.getNewMaintainableObject().getBusinessObject();

		List<AssetGlobalDetail> assetSharedDetails = assetGlobal.getAssetSharedDetails();
		int sharedIndex = 0;
		int uniqueIndex = 0;

		if (!assetSharedDetails.isEmpty() && !assetSharedDetails.get(0).getAssetGlobalUniqueDetails().isEmpty()) {
			for (AssetGlobalDetail locationDetail : assetSharedDetails) {
				List<AssetGlobalDetail> assetGlobalUniqueDetails = locationDetail.getAssetGlobalUniqueDetails();
				for (AssetGlobalDetail unique : assetGlobalUniqueDetails) {
					AssetGlobalDetailExtension assetGlobalDetailExtension = (AssetGlobalDetailExtension) unique.getExtension();
					assetGlobalDetailExtension.refreshReferenceObject(CamsPropertyConstants.AssetGlobalExtension.ASSET_INVENTORY_UNIT_OBJECT);
					AssetInventoryUnit invUnit = assetGlobalDetailExtension.getAssetInvUnitObj();

					String errorPath = MAINTAINABLE_ERROR_PREFIX + CamsPropertyConstants.AssetGlobal.ASSET_SHARED_DETAILS + "[" + sharedIndex + "]." + CamsPropertyConstants.AssetGlobalDetail.ASSET_UNIQUE_DETAILS + "[" + uniqueIndex + "]";
					GlobalVariables.getMessageMap().addToErrorPath(errorPath);

					if (ObjectUtils.isNull(invUnit)) {
						GlobalVariables.getMessageMap().putError(CamsPropertyConstants.AssetGlobalExtension.EXTENSION_INVENTORY_UNIT_CODE, CamsKeyConstants.ERROR_INVENTORY_UNIT_CODE_NOT_EXIST, CamsConstants.AssetGlobal.ASSET_INVENTORY_UNIT_NULL);
						success = false;
					}
					else {
						BusinessObjectService bos = SpringContext.getBean(BusinessObjectService.class);
						Map<String, String> fieldValues = new HashMap<String, String>();
						fieldValues.put(KFSPropertyConstants.INVENTORY_UNIT_CODE, invUnit.getInventoryUnitCode());<commit_msg>UAF-32 UAF-3686 Inventory Unit Fields Step 4 Asset Global Validations - PR suggestions<commit_after>package edu.arizona.kfs.module.cam.document.validation.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.kuali.kfs.module.cam.businessobject.AssetGlobal;
import org.kuali.kfs.module.cam.businessobject.AssetGlobalDetail;
import org.kuali.kfs.sys.KFSConstants;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.rice.kns.document.MaintenanceDocument;
import org.kuali.rice.krad.service.BusinessObjectService;
import org.kuali.rice.krad.util.GlobalVariables;
import org.kuali.rice.krad.util.ObjectUtils;

import edu.arizona.kfs.module.cam.CamsConstants;
import edu.arizona.kfs.module.cam.CamsKeyConstants;
import edu.arizona.kfs.module.cam.CamsPropertyConstants;
import edu.arizona.kfs.module.cam.businessobject.AssetGlobalDetailExtension;
import edu.arizona.kfs.module.cam.businessobject.AssetInventoryUnit;
import edu.arizona.kfs.sys.KFSPropertyConstants;

public class AssetGlobalRule extends org.kuali.kfs.module.cam.document.validation.impl.AssetGlobalRule {

	@Override
	protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
		boolean success = true;
		success &= super.processCustomSaveDocumentBusinessRules(document);

		AssetGlobal assetGlobal = (AssetGlobal) document.getNewMaintainableObject().getBusinessObject();

		if (GlobalVariables.getMessageMap().hasErrors()) {
			return false;
		}

		List<AssetGlobalDetail> assetSharedDetails = assetGlobal.getAssetSharedDetails();
		int sharedIndex = 0;
		int uniqueIndex = 0;

		if (!assetSharedDetails.isEmpty() && !assetSharedDetails.get(0).getAssetGlobalUniqueDetails().isEmpty()) {
			for (AssetGlobalDetail locationDetail : assetSharedDetails) {
				List<AssetGlobalDetail> assetGlobalUniqueDetails = locationDetail.getAssetGlobalUniqueDetails();
				for (AssetGlobalDetail unique : assetGlobalUniqueDetails) {
					AssetGlobalDetailExtension assetGlobalDetailExtension = (AssetGlobalDetailExtension) unique.getExtension();
					assetGlobalDetailExtension.refreshReferenceObject(CamsPropertyConstants.AssetGlobalExtension.ASSET_INVENTORY_UNIT_OBJECT);
					AssetInventoryUnit invUnit = assetGlobalDetailExtension.getAssetInvUnitObj();

					String errorPath = MAINTAINABLE_ERROR_PREFIX + CamsPropertyConstants.AssetGlobal.ASSET_SHARED_DETAILS + "[" + sharedIndex + "]." + CamsPropertyConstants.AssetGlobalDetail.ASSET_UNIQUE_DETAILS + "[" + uniqueIndex + "]";
					GlobalVariables.getMessageMap().addToErrorPath(errorPath);

					if (ObjectUtils.isNull(invUnit)) {
						GlobalVariables.getMessageMap().putError(CamsPropertyConstants.AssetGlobalExtension.EXTENSION_INVENTORY_UNIT_CODE, CamsKeyConstants.ERROR_INVENTORY_UNIT_CODE_NOT_EXIST, CamsConstants.AssetGlobal.ASSET_INVENTORY_UNIT_NULL);
						success = false;
					}
					else {
						BusinessObjectService bos = SpringContext.getBean(BusinessObjectService.class);
						Map<String, String> fieldValues = new HashMap<String, String>();
						fieldValues.put(KFSPropertyConstants.INVENTORY_UNIT_CODE, invUnit.getInventoryUnitCode());
{'fraction_non_alphanumeric': 0.0947913296667745, 'fraction_numerical': 0.0021028793270786153, 'mean_word_length': 6.690298507462686, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5330417', 'n_tokens_mistral': 2015, 'n_tokens_neox': 1819, 'n_words': 244}