001/*
002 * (C) Copyright 2018 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 *
016 * Contributors:
017 *     Funsho David
018 */
019
020package org.nuxeo.ecm.annotation;
021
022import static org.nuxeo.ecm.annotation.AnnotationConstants.ANNOTATION_DOCUMENT_ID;
023import static org.nuxeo.ecm.annotation.AnnotationConstants.ANNOTATION_ENTITY;
024import static org.nuxeo.ecm.annotation.AnnotationConstants.ANNOTATION_ID;
025import static org.nuxeo.ecm.annotation.AnnotationConstants.ANNOTATION_XPATH;
026import static org.nuxeo.ecm.annotation.AnnotationJsonWriter.ENTITY_TYPE;
027import static org.nuxeo.ecm.core.io.registry.reflect.Instantiations.SINGLETON;
028import static org.nuxeo.ecm.core.io.registry.reflect.Priorities.REFERENCE;
029
030import java.io.IOException;
031
032import org.nuxeo.ecm.core.io.marshallers.json.EntityJsonReader;
033import org.nuxeo.ecm.core.io.registry.reflect.Setup;
034
035import com.fasterxml.jackson.databind.JsonNode;
036
037/**
038 * @since 10.1
039 */
040@Setup(mode = SINGLETON, priority = REFERENCE)
041public class AnnotationJsonReader extends EntityJsonReader<Annotation> {
042
043    public AnnotationJsonReader() {
044        super(ENTITY_TYPE);
045    }
046
047    @Override
048    protected Annotation readEntity(JsonNode jn) throws IOException {
049        Annotation annotation = new AnnotationImpl();
050        annotation.setId(jn.get(ANNOTATION_ID).textValue());
051        annotation.setDocumentId(jn.get(ANNOTATION_DOCUMENT_ID).textValue());
052        annotation.setXpath(jn.get(ANNOTATION_XPATH).textValue());
053        annotation.setEntity(jn.get(ANNOTATION_ENTITY).textValue());
054
055        return annotation;
056    }
057
058}