001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kns.service.impl;
017
018import org.apache.commons.collections.CollectionUtils;
019import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition;
020import org.kuali.rice.kns.util.documentserlializer.MaintenanceDocumentPropertySerializibilityEvaluator;
021import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry;
022import org.kuali.rice.krad.util.documentserializer.AlwaysTruePropertySerializibilityEvaluator;
023import org.kuali.rice.krad.util.documentserializer.PropertySerializabilityEvaluator;
024
025import java.util.List;
026
027/**
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030public class BusinessObjectSerializerServiceImpl extends org.kuali.rice.krad.service.impl.BusinessObjectSerializerServiceImpl {
031
032    @Override
033    public PropertySerializabilityEvaluator getPropertySerizabilityEvaluator(Object businessObject) {
034        PropertySerializabilityEvaluator evaluator = null;
035
036        String docTypeName = getDocumentDictionaryService().getMaintenanceDocumentTypeName(businessObject.getClass());
037        MaintenanceDocumentEntry maintenanceDocumentEntry =
038                getDocumentDictionaryService().getMaintenanceDocumentEntry(docTypeName);
039
040        if (maintenanceDocumentEntry instanceof org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry) {
041            List<MaintainableSectionDefinition> maintainableSectionDefinitions =
042                    ((org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry) maintenanceDocumentEntry).getMaintainableSections();
043            if (CollectionUtils.isEmpty(maintainableSectionDefinitions)) {
044                evaluator = new AlwaysTruePropertySerializibilityEvaluator();
045            } else {
046                evaluator = new MaintenanceDocumentPropertySerializibilityEvaluator();
047                evaluator.initializeEvaluatorForDataObject(businessObject);
048            }
049        }
050        else {
051           evaluator = new AlwaysTruePropertySerializibilityEvaluator();
052        }
053
054        return evaluator;
055    }
056}