001/* 002 * (C) Copyright 2014 Nuxeo SA (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 * vpasquier <vpasquier@nuxeo.com> 018 */ 019package org.nuxeo.binary.metadata.api; 020 021import java.util.List; 022import java.util.Map; 023 024import org.nuxeo.binary.metadata.internals.MetadataMappingDescriptor; 025import org.nuxeo.ecm.core.api.Blob; 026import org.nuxeo.ecm.core.api.CoreSession; 027import org.nuxeo.ecm.core.api.DocumentModel; 028import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 029 030/** 031 * Read/Write binary metadata services. 032 * 033 * @since 7.1 034 */ 035public interface BinaryMetadataService { 036 037 /** 038 * Read and return metadata from a given binary and a given metadata list with a given processor. 039 * 040 * @param processorName Name of the contributed processor to run. 041 * @param blob Binary which metadata are read. 042 * @param metadataNames Metadata list to extract from the binary. 043 * @param ignorePrefix Since 7.3 044 * @return Extracted metadata. 045 */ 046 public Map<String, Object> readMetadata(String processorName, Blob blob, List<String> metadataNames, 047 boolean ignorePrefix); 048 049 /** 050 * Read and return metadata from a given binary and a given metadata list with Nuxeo default processor. 051 * 052 * @param blob Binary which metadata are read. 053 * @param metadataNames Metadata list to extract from the binary. 054 * @param ignorePrefix Since 7.3 055 * @return Extracted metadata. 056 */ 057 public Map<String, Object> readMetadata(Blob blob, List<String> metadataNames, boolean ignorePrefix); 058 059 /** 060 * Read and return metadata from a given binary with Nuxeo default processor. 061 * 062 * @param blob Binary which metadata are read. 063 * @param ignorePrefix Since 7.3 064 * @return Extracted metadata. 065 */ 066 public Map<String, Object> readMetadata(Blob blob, boolean ignorePrefix); 067 068 /** 069 * Read and return metadata from a given binary with a given processor. 070 * 071 * @param processorName Name of the contributed processor to run. 072 * @param blob Binary which metadata are read. 073 * @param ignorePrefix Since 7.3 074 * @return Extracted metadata. 075 */ 076 public Map<String, Object> readMetadata(String processorName, Blob blob, boolean ignorePrefix); 077 078 /** 079 * Write given metadata into a given binary with a given processor. 080 * 081 * @param processorName Name of the contributed processor to run. 082 * @param blob Binary which metadata are written. 083 * @param metadata Injected metadata. 084 * @param ignorePrefix Since 7.3 085 * @return the updated blob, or {@code null} if there was an error (since 7.4) 086 */ 087 public Blob writeMetadata(String processorName, Blob blob, Map<String, Object> metadata, boolean ignorePrefix); 088 089 /** 090 * Write given metadata into a given binary with a Nuxeo default processor. 091 * 092 * @param blob Binary which metadata are written. 093 * @param metadata Injected metadata. 094 * @param ignorePrefix Since 7.3 095 * @return the updated blob, or {@code null} if there was an error (since 7.4) 096 */ 097 public Blob writeMetadata(Blob blob, Map<String, Object> metadata, boolean ignorePrefix); 098 099 /** 100 * Write given metadata mapping id into a given binary with a Nuxeo default processor. 101 * 102 * @param processorName Name of the contributed processor to run. 103 * @param blob Binary which metadata are written. 104 * @param mappingDescriptorId The metadata mapping to apply on the document. 105 * @param doc Document from properties will be read. 106 * @return the updated blob, or {@code null} if there was an error (since 7.4) 107 */ 108 public Blob writeMetadata(String processorName, Blob blob, String mappingDescriptorId, DocumentModel doc); 109 110 /** 111 * Write given metadata mapping id into a given binary with a Nuxeo default processor. 112 * 113 * @param blob Binary which metadata are written. 114 * @param mappingDescriptorId The metadata mapping to apply on the document. 115 * @param doc Document from properties will be read. 116 * @return the updated blob, or {@code null} if there was an error (since 7.4) 117 */ 118 public Blob writeMetadata(Blob blob, String mappingDescriptorId, DocumentModel doc); 119 120 /** 121 * Write metadata (from a binary) into a given Nuxeo Document according to the metadata mapping and rules 122 * contributions. 123 * 124 * @param doc Nuxeo Document which metadata are written. 125 */ 126 public void writeMetadata(DocumentModel doc, CoreSession session); 127 128 /** 129 * Apply metadata mapping and override document properties according to the contribution. 130 * 131 * @param doc The input document. 132 * @param session core session. 133 * @param mappingDescriptorId The metadata mapping to apply on the document. 134 */ 135 public void writeMetadata(DocumentModel doc, CoreSession session, String mappingDescriptorId); 136 137 /** 138 * Handle document and blob updates according to following rules in an event context: - Define if rule should be 139 * executed in async or sync mode. - If Blob dirty and document metadata dirty, write metadata from doc to Blob. - 140 * If Blob dirty and document metadata not dirty, write metadata from Blob to doc. - If Blob not dirty and document 141 * metadata dirty, write metadata from doc to Blob. 142 */ 143 void handleUpdate(List<MetadataMappingDescriptor> syncMappingDescriptors, DocumentModel doc, 144 DocumentEventContext docCtx); 145 146 /** 147 * Handle document and blob updates according to following rules in an event context: - Define if rule should be 148 * executed in async or sync mode. - If Blob dirty and document metadata dirty, write metadata from doc to Blob. - 149 * If Blob dirty and document metadata not dirty, write metadata from Blob to doc. - If Blob not dirty and document 150 * metadata dirty, write metadata from doc to Blob. 151 */ 152 void handleSyncUpdate(DocumentModel doc, DocumentEventContext docCtx); 153 154}