001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *      Vladimir Pasquier <vpasquier@nuxeo.com>
016 */
017package org.nuxeo.binary.metadata.internals.operations;
018
019import org.nuxeo.binary.metadata.api.BinaryMetadataService;
020import org.nuxeo.ecm.automation.OperationContext;
021import org.nuxeo.ecm.automation.core.Constants;
022import org.nuxeo.ecm.automation.core.annotations.Context;
023import org.nuxeo.ecm.automation.core.annotations.Operation;
024import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
025import org.nuxeo.ecm.automation.core.annotations.Param;
026import org.nuxeo.ecm.core.api.DocumentModel;
027
028/**
029 * @since 7.1
030 */
031@Operation(id = TriggerMetadataMappingOnDocument.ID, category = Constants.CAT_BLOB, label = "Trigger Metadata Mapping", description = "Write Metadata To Document From Binary according to metadata mapping.", since = "7.1", addToStudio = true, aliases = { "Document.TriggerMetadataMapping" })
032public class TriggerMetadataMappingOnDocument {
033
034    public static final String ID = "Document.SetMetadataFromBlob";
035
036    @Context
037    protected BinaryMetadataService binaryMetadataService;
038
039    @Context
040    protected OperationContext operationContext;
041
042    @Param(name = "processor", required = false, description = "The processor to execute for reading blobs metadata.")
043    protected String processor = "exifTool";
044
045    @Param(name = "metadataMappingId", required = true, description = "The metadata mapping id to apply on the input document.")
046    protected String metadataMappingId;
047
048    @OperationMethod
049    public void run(DocumentModel document) {
050        binaryMetadataService.writeMetadata(document, operationContext.getCoreSession(), metadataMappingId);
051    }
052}