001package ball.tv.epg.entity;
002/*-
003 * ##########################################################################
004 * TV H/W, EPGs, and Recording
005 * $Id: AbstractEntity.java 5285 2020-02-05 04:23:21Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/ball-tv/trunk/src/main/java/ball/tv/epg/entity/AbstractEntity.java $
007 * %%
008 * Copyright (C) 2013 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import ball.persistence.entity.JSONEntity;
024import ball.tv.ObjectMapperConfiguration;
025import com.fasterxml.jackson.databind.JsonNode;
026import javax.persistence.MappedSuperclass;
027import lombok.NoArgsConstructor;
028
029import static lombok.AccessLevel.PROTECTED;
030
031/**
032 * Abstract {@link ball.tv.epg.entity} {@link JSONEntity} base class.
033 *
034 * {@bean.info}
035 *
036 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
037 * @version $Revision: 5285 $
038 */
039@MappedSuperclass
040@NoArgsConstructor(access = PROTECTED)
041public abstract class AbstractEntity extends JSONEntity {
042    private static final long serialVersionUID = 8798994064011298347L;
043
044    { mapper = ObjectMapperConfiguration.MAPPER; }
045
046    @Override
047    public JsonNode asJsonNode() {
048        JsonNode node = super.asJsonNode();
049
050        if (node == null) {
051            String json = getJson();
052
053            if (json != null) {
054                try {
055                    node = mapper.readTree(json);
056                    super.node = node;
057                } catch (Exception exception) {
058                }
059            }
060        }
061
062        return node;
063    }
064}