Search in sources :

Example 1 with Room

use of org.kuali.kfs.sys.businessobject.Room in project cu-kfs by CU-CommunityApps.

the class CuCapitalAssetManagementModuleServiceImpl method validateAssetTagLocationLines.

protected boolean validateAssetTagLocationLines(CapitalAssetInformation capitalAssetInformation, int capitalAssetIndex, AccountingDocument accountingDocument) {
    boolean valid = true;
    CapitalAssetEditable capitalAssetEditable = (CapitalAssetEditable) accountingDocument;
    List<CapitalAssetInformation> capitalAssets = capitalAssetEditable.getCapitalAssetInformation();
    List<CapitalAssetInformationDetail> capitalAssetInformationDetails = capitalAssetInformation.getCapitalAssetInformationDetails();
    int index = 0;
    for (CapitalAssetInformationDetail dtl : capitalAssetInformationDetails) {
        CapitalAssetInformationDetailExtendedAttribute capDetailExt = (CapitalAssetInformationDetailExtendedAttribute) dtl.getExtension();
        String assetLocationCityName = capDetailExt.getAssetLocationCityName();
        String assetLocationCountryCode = capDetailExt.getAssetLocationCountryCode();
        String assetLocationStateCode = capDetailExt.getAssetLocationStateCode();
        String assetLocationStreetAddress = capDetailExt.getAssetLocationStreetAddress();
        String assetLocationZipCode = capDetailExt.getAssetLocationZipCode();
        // We have to explicitly call this DD service to upper case each field. This may not be the best place and maybe form
        // populate is a better place but we CAMS team don't own FP document. This is the best we can do for now.
        businessObjectDictionaryService.performForceUppercase(dtl);
        String errorPathPrefix = KFSPropertyConstants.DOCUMENT + "." + KFSPropertyConstants.CAPITAL_ASSET_INFORMATION + "[" + capitalAssetIndex + "]." + KFSPropertyConstants.CAPITAL_ASSET_INFORMATION_DETAILS;
        if (StringUtils.isNotBlank(dtl.getCampusCode())) {
            Campus campus = campusService.getCampus(dtl.getCampusCode());
            if (ObjectUtils.isNull(campus)) {
                valid = false;
                String label = this.getDataDictionaryService().getAttributeLabel(Campus.class, KFSPropertyConstants.CODE);
                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.CAMPUS_CODE, KFSKeyConstants.ERROR_EXISTENCE, label);
            }
        }
        Map<String, String> params;
        if (StringUtils.isNotBlank(dtl.getCampusCode()) && StringUtils.isNotBlank(dtl.getBuildingCode()) && StringUtils.isBlank(assetLocationCityName) && StringUtils.isBlank(assetLocationStateCode) && StringUtils.isBlank(assetLocationCountryCode) && StringUtils.isBlank(assetLocationStreetAddress) && StringUtils.isBlank(assetLocationZipCode)) {
            params = new HashMap<String, String>();
            params.put(KFSPropertyConstants.CAMPUS_CODE, dtl.getCampusCode());
            params.put(KFSPropertyConstants.BUILDING_CODE, dtl.getBuildingCode());
            Building building = businessObjectService.findByPrimaryKey(Building.class, params);
            // Check if building is valid
            if (ObjectUtils.isNull(building)) {
                valid = false;
                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.BUILDING_CODE, CamsKeyConstants.AssetLocationGlobal.ERROR_INVALID_BUILDING_CODE, dtl.getBuildingCode(), dtl.getCampusCode());
            }
        }
        AssetType assetType = getAssetType(capitalAssetInformation.getCapitalAssetTypeCode());
        if (StringUtils.isBlank(assetLocationCityName) && StringUtils.isBlank(assetLocationStateCode) && StringUtils.isBlank(assetLocationCountryCode) && StringUtils.isBlank(assetLocationStreetAddress) && StringUtils.isBlank(assetLocationZipCode)) {
            // If building was specified but was not required for this asset type display an error
            if (StringUtils.isNotBlank(dtl.getBuildingCode()) && ObjectUtils.isNotNull(assetType) && !assetType.isMovingIndicator() && !assetType.isRequiredBuildingIndicator()) {
                valid = false;
                String label = this.getDataDictionaryService().getAttributeLabel(Building.class, KFSPropertyConstants.BUILDING_CODE);
                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.BUILDING_CODE, CamsKeyConstants.AssetLocation.ERROR_ASSET_LOCATION_BUILDING_NONMOVEABLE, label);
            }
            if (StringUtils.isNotBlank(dtl.getCampusCode()) && StringUtils.isNotBlank(dtl.getBuildingCode()) && StringUtils.isNotBlank(dtl.getBuildingRoomNumber())) {
                params = new HashMap<>();
                params.put(KFSPropertyConstants.CAMPUS_CODE, dtl.getCampusCode());
                params.put(KFSPropertyConstants.BUILDING_CODE, dtl.getBuildingCode());
                params.put(KFSPropertyConstants.BUILDING_ROOM_NUMBER, dtl.getBuildingRoomNumber());
                Room room = businessObjectService.findByPrimaryKey(Room.class, params);
                // Check if room is valid
                if (ObjectUtils.isNull(room)) {
                    valid = false;
                    GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.BUILDING_ROOM_NUMBER, CamsKeyConstants.AssetLocationGlobal.ERROR_INVALID_ROOM_NUMBER, dtl.getBuildingRoomNumber(), dtl.getBuildingCode(), dtl.getCampusCode());
                }
            }
            // If room was specified but was not required for this asset type display an error
            if (StringUtils.isNotBlank(dtl.getBuildingRoomNumber()) && ObjectUtils.isNotNull(assetType) && !assetType.isMovingIndicator()) {
                valid = false;
                String label = this.getDataDictionaryService().getAttributeLabel(Room.class, KFSPropertyConstants.BUILDING_ROOM_NUMBER);
                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.BUILDING_ROOM_NUMBER, CamsKeyConstants.AssetLocation.ERROR_ASSET_LOCATION_ROOM_NUMBER_NONMOVEABLE, label);
            }
        }
        index++;
    }
    return valid;
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) Building(org.kuali.kfs.sys.businessobject.Building) Campus(org.kuali.rice.location.api.campus.Campus) CapitalAssetInformationDetail(org.kuali.kfs.fp.businessobject.CapitalAssetInformationDetail) CapitalAssetEditable(org.kuali.kfs.fp.document.CapitalAssetEditable) AssetType(org.kuali.kfs.module.cam.businessobject.AssetType) CapitalAssetInformationDetailExtendedAttribute(edu.cornell.kfs.fp.businessobject.CapitalAssetInformationDetailExtendedAttribute) Room(org.kuali.kfs.sys.businessobject.Room)

Aggregations

CapitalAssetInformationDetailExtendedAttribute (edu.cornell.kfs.fp.businessobject.CapitalAssetInformationDetailExtendedAttribute)1 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)1 CapitalAssetInformationDetail (org.kuali.kfs.fp.businessobject.CapitalAssetInformationDetail)1 CapitalAssetEditable (org.kuali.kfs.fp.document.CapitalAssetEditable)1 AssetType (org.kuali.kfs.module.cam.businessobject.AssetType)1 Building (org.kuali.kfs.sys.businessobject.Building)1 Room (org.kuali.kfs.sys.businessobject.Room)1 Campus (org.kuali.rice.location.api.campus.Campus)1