package org.nuxeo.ecm.automation.core.operations.business.adapter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelFactory;

/**
 * Nuxeo document model abstract adapter to extend for mapping
 *
 * @since 5.7
 */
public abstract class BusinessAdapter {

    private static final Log log = LogFactory.getLog(BusinessAdapter.class);

    protected transient DocumentModel doc;

    @JsonProperty("id")
    protected String id;

    public BusinessAdapter() {
        this.doc = DocumentModelFactory.createDocumentModel("File");
        this.id = doc.getId();
    }

    public BusinessAdapter(DocumentModel document) {
        this.doc = document;
        this.id = doc.getId();
    }

    public void save(CoreSession session) {
        try {
            session.saveDocument(doc);
            session.save();
        } catch (ClientException e) {
            log.error("Cannot save document", e);
        }
    }

    @JsonIgnore
    public DocumentModel getDocument() {
        return doc;
    }

    public String getId() {
        return doc.getId();
    }

}

@@ -1,8 +1,674 @@
+/*%0A * (C) Copyright 2006-2013 Nuxeo SAS (http://nuxeo.com/) and contributors.%0A *%0A * All rights reserved. This program and the accompanying materials%0A * are made available under the terms of the GNU Lesser General Public License%0A * (LGPL) version 2.1 which accompanies this distribution, and is available at%0A * http://www.gnu.org/licenses/lgpl.html%0A *%0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU%0A * Lesser General Public License for more details.%0A *%0A * Contributors:%0A *     vpasquier %3Cvpasquier@nuxeo.com%3E%0A */%0A
 package 

add missing licence