001/**
002 * Copyright 2005-2017 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.krms.impl.repository.jpa;
017
018import org.kuali.rice.krms.api.repository.typerelation.RelationshipType;
019
020import javax.persistence.AttributeConverter;
021import javax.persistence.Converter;
022
023/**
024 * A JPA converter that converts String code values to corresponding RelationshipType
025 *
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028@Converter
029public class RelationshipTypeConverter implements AttributeConverter<RelationshipType, String> {
030
031    @Override
032    public String convertToDatabaseColumn(RelationshipType objectValue) {
033        if (objectValue != null) {
034            return objectValue.getCode();
035        }
036
037        return null;
038    }
039
040    @Override
041    public RelationshipType convertToEntityAttribute(String dataValue) {
042        RelationshipType result = null;
043
044        if (dataValue != null) {
045            result = RelationshipType.fromCode(dataValue);
046        }
047
048        return result;
049    }
050}