Extractor de metadatos

cancel
Showing results for 
Search instead for 
Did you mean: 
ruben_arjonilla
Member II

Extractor de metadatos

Buenas,

Tengo algunas dudas sobre los extractores de metadatos de los archivos.

A mi entender, un extractor de metadatos lo que hace es poner unos metadatos que trae un fichero en propiedades que pueden ser creadas por uno mismo.

En mi caso, quiero poner los metadatos que traen los ficheros de imagen, dimensiones, marca de la cámara, modelo, fecha en que se tomó, valor de apertura, longitud focal, etc.. en un tipo de archivo creado por mi, en mi caso img:imagen, que tiene las sigüientes propiedades (pongo directamente el modelo):

<type name="img:imagen">
         <title>Imagen</title>
         <parent>cm:content</parent>
         <properties>
            <property name="img:descripcion">
               <title>Descripción</title>
               <description>Breve descripción de la imagen.</description>
               <type>d:text</type>
               <mandatory>true</mandatory>
               <default></default>
            </property>
            <property name="img:medidaX">
               <title>Ancho de la imagen</title>
               <description>Ancho de la imagen</description>
               <type>d:text</type>
               <mandatory>true</mandatory>
               <default></default>
            </property>
            <property name="img:medidaY">
               <title>Altura de la imagen</title>
               <description>Altura de la imagen</description>
               <type>d:text</type>
               <mandatory>true</mandatory>
               <default></default>
            </property>
            <property name="img:resolucion">
               <title>Resolución</title>
               <description>Resolución de la imagen.</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <!– property name="img:fecha">
               <title>Fecha de la imagen</title>
               <description>Fecha de la imagen</description>
               <type>d:datetime</type>
               <mandatory>false</mandatory>
               <default></default>
            </property –>
            <property name="img:latitud">
               <title>Latitud de la imagen</title>
               <description>Latitud de la imagen</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:longitud">
               <title>Longitud de la imagen</title>
               <description>Longitud de la imagen</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:tiempoExposicion">
               <title>Tiempo de exposición</title>
               <description>Tiempo de exposición</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:apertura">
               <title>Valor de apertura de la imagen</title>
               <description>Valor de apertura de la imagen</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:velocidadISO">
               <title>Tasa de velocidad ISO de la imagen</title>
               <description>Tasa de velocidad ISO de la imagen</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:flash">
               <title>Con Flash</title>
               <description>Con Flash</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:modoMedida">
               <title>Modo de medida de la imagen</title>
               <description>Modo de medida de la imagen</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:programaExposicion">
               <title>Programa de exposición de la imagen</title>
               <description>Programa de exposición de la imagen</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:longitudFocal">
               <title>Longitud focal de la imagen</title>
               <description>Longitud focal de la imagen</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:software">
               <title>Software de la imagen</title>
               <description>Software de la imagen</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
            <property name="img:copyright">
               <title>Copyright de la imagen</title>
               <description>Copyright de la imagen</description>
               <type>d:text</type>
               <mandatory>false</mandatory>
               <default></default>
            </property>
           </properties>
          
           <!–associations>
         </associations–>
         <mandatory-aspects>
            <aspect>cm:taggable</aspect>
           </mandatory-aspects>
      </type>


Según entiendo, el extractor debería coger los metadatos del fichero, y ir poniéndolos dentro de las propiedades del tipo de archivo img:imagen
y este es mi extractor:

/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package com.metadataExtraction;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.TikaPoweredMetadataExtracter;
import org.alfresco.service.namespace.QName;
import org.apache.log4j.Logger;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.metadata.XMPDM;
import org.apache.tika.parser.Parser;
import org.apache.tika.parser.image.ImageParser;


/**
* Extracts the following values from img files:
* <pre>
*   <b>descripcion:</b>            –      {img}:descripcion
*   <b>medidaX:</b>                –      {img}:medidaX
*   <b>medidaY:</b>                –      {img}:medidaY
*   <b>resolucion:</b>             –      {img}:resolucion
*   <b>fecha:</b>                  –      {img}:fecha
*   <b>latitud:</b>                –      {img}:latitud
*   <b>longitud:</b>                 –      {img}:longitud
*   <b>tiempoExposicion:</b>       –      {img}:tiempoExposicion
*   <b>apertura:</b>                 –      {img}:apertura
*   <b>velocidadISO:</b>           –      {img}:velocidadISO
*   <b>flash:</b>                 –      {img}:flash
*   <b>modoMedida:</b>             –      {img}:modoMedida
*   <b>programaExposicion:</b>     –      {img}:programaExposicion
*   <b>longitudFocal:</b>          –      {img}:longitudFocal
*   <b>software:</b>                 –      {img}:software
*   <b>copyright:</b>              –      {img}:copyright
* </pre>
*
*
* Uses Apache Tika
*
* @author Nick Burch
* @author Roy Wetherall
*/
public class ImgMetadataExtracter extends TikaPoweredMetadataExtracter
{
   private Logger logger = Logger.getLogger(ImgMetadataExtracter.class);
   
    private static final String KEY_IMG_MEDIDAX = "medidaX";
    private static final String KEY_IMG_MEDIDAY = "medidaY";
    private static final String KEY_IMG_RESOLUCION = "resolucion";
    private static final String KEY_IMG_FECHA = "fecha";
    private static final String KEY_IMG_LATITUD = "latitud";
    private static final String KEY_IMG_LONGITUD = "longitud";
    private static final String KEY_IMG_TIEMPO_EXPOSICION = "tiempoExposicion";
    private static final String KEY_IMG_APERTURA = "apertura";
    private static final String KEY_IMG_VELOCIDAD_ISO = "velocidadISO";
    private static final String KEY_IMG_FLASH = "flash";
    private static final String KEY_IMG_MODO_MEDIDA = "modoMedida";
    private static final String KEY_IMG_PROGRAMA_EXPOSICION = "programaExposicion";
    private static final String KEY_IMG_LONGITUD_FOCAL = "longitudFocal";
    private static final String KEY_IMG_SOFTWARE = "software";
    private static final String KEY_IMG_COPYRIGHT = "copyright";
   
    private static final String CUSTOM_PREFIX = "img:";
   
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
   
    /*
    medidaX
    medidaY
    resolucion
    fecha
    latitud
    longitud
    tiempoExposicion
    apertura
    velocidadISO
    flash
    modoMedida
    programaExposicion
    longitudFocal
    software
    copyright
    */

    public static String[] SUPPORTED_MIMETYPES = new String[] {
          MimetypeMap.MIMETYPE_IMAGE_GIF,
          MimetypeMap.MIMETYPE_IMAGE_JPEG,
          MimetypeMap.MIMETYPE_IMAGE_PNG,
          MimetypeMap.MIMETYPE_IMAGE_RGB,
          MimetypeMap.MIMETYPE_IMAGE_SVG,
          MimetypeMap.MIMETYPE_OPENDOCUMENT_GRAPHICS,
          MimetypeMap.MIMETYPE_OPENDOCUMENT_IMAGE,
    };
   
    public ImgMetadataExtracter()
    {
//        super(SUPPORTED_MIMETYPES);
        super(new HashSet<String>(Arrays.asList(SUPPORTED_MIMETYPES)));
        logger.debug("Initializing ImgMetadataExtracter logger constructor");
    }
   
    @Override
    protected Map<String, Serializable> extractSpecific(Metadata metadata, Map<String, Serializable> properties, Map<String,String> headers) {
//       putRawValue(KEY_IMG_MEDIDAX, metadata.get(XMPDM.ALBUM), properties);
//       putRawValue(KEY_SONG_TITLE, metadata.get(Metadata.TITLE), properties);
//       putRawValue(KEY_ARTIST, metadata.get(TIFF.ARTIST), properties);
      
       putRawValue(KEY_IMG_MEDIDAX, metadata.get(Metadata.IMAGE_WIDTH), properties);
       putRawValue(KEY_IMG_MEDIDAY, metadata.get(Metadata.IMAGE_LENGTH), properties);
       putRawValue(KEY_IMG_RESOLUCION, metadata.get(Metadata.RESOLUTION_HORIZONTAL), properties);
      
//       putRawValue(KEY_IMG_FECHA, getDateOrNull(metadata.get(Metadata.CREATION_DATE)), properties);
//       putRawValue(KEY_IMG_FECHA, getDateOrNull(metadata.get(Metadata.ORIGINAL_DATE)), properties);
//       putRawValue(KEY_IMG_FECHA, metadata.get(Metadata.ORIGINAL_DATE), properties);
       putRawValue(KEY_IMG_LATITUD, metadata.get(Metadata.LATITUDE), properties);
       putRawValue(KEY_IMG_LONGITUD, metadata.get(Metadata.ALTITUDE), properties);
       putRawValue(KEY_IMG_TIEMPO_EXPOSICION, metadata.get(Metadata.EXPOSURE_TIME), properties);
//       putRawValue(KEY_IMG_APERTURA, metadata.get(TIFF.ALBUM), properties);
       putRawValue(KEY_IMG_VELOCIDAD_ISO, metadata.get(Metadata.ISO_SPEED_RATINGS), properties);
       putRawValue(KEY_IMG_FLASH, metadata.get(Metadata.FLASH_FIRED), properties);
//       putRawValue(KEY_IMG_MODO_MEDIDA, metadata.get(TIFF.ALBUM), properties);
//       putRawValue(KEY_IMG_PROGRAMA_EXPOSICION, metadata.get(Tiff.ALBUM), properties);
       putRawValue(KEY_IMG_LONGITUD_FOCAL, metadata.get(Metadata.FOCAL_LENGTH), properties);
       putRawValue(KEY_IMG_SOFTWARE, metadata.get(Metadata.SOFTWARE), properties);

//       putRawValue(KEY_IMG_COPYRIGHT, metadata.get(XMPDM.COPYRIGHT), properties);
      putRawValue(KEY_IMG_COPYRIGHT, "probando copyright", properties);
      putRawValue(CUSTOM_PREFIX+KEY_IMG_COPYRIGHT, "probando copyright 2", properties);
      
      putRawValue("a", getDateOrNull(metadata.get(Metadata.CREATION_DATE)), properties);
      putRawValue("b", getDateOrNull(metadata.get(Metadata.ORIGINAL_DATE)), properties);
      
      putRawValue(KEY_AUTHOR, metadata.get(Metadata.AUTHOR), properties);
        putRawValue(KEY_TITLE, metadata.get(Metadata.TITLE), properties);
        putRawValue(KEY_COMMENTS, metadata.get(Metadata.COMMENTS), properties);
       
      
       logger.debug("Poniendo datos?");
       logger.debug("KEY_IMG_MEDIDAX: "+KEY_IMG_MEDIDAX);
       logger.debug("Metadata.IMAGE_WIDTH.toString(): "+Metadata.IMAGE_WIDTH.toString());
       logger.debug("metadata.get(Metadata.IMAGE_WIDTH): "+metadata.get(Metadata.IMAGE_WIDTH));
       logger.debug("properties: "+properties.toString());
//       logger.debug("headers: "+headers.toString());
      
    // Handle user-defined properties dynamically
//       logger.debug("headers: "+headers.values().toString());
//       logger.debug("headers");
//       for (String key : headers.keySet())
//       {
//          logger.debug("key: "+key);
//          logger.debug("get key: "+headers.get(key));
//       }
      
       logger.debug("Map");
       Map<String, Set<QName>> mapping = super.getMapping();
       for (String key : mapping.keySet())
       {
          logger.debug("key: "+key);
           if (metadata.get(CUSTOM_PREFIX + key) != null)
           {
              logger.debug("dentro if key");
                putRawValue(key, metadata.get(CUSTOM_PREFIX + key), properties);
           }
       }
      
       logger.debug("Fi for Map");
      
      
       logger.debug(metadata.get(Metadata.TITLE));
       logger.debug(metadata.get(Metadata.CREATION_DATE));
       logger.debug(metadata.get(Metadata.CREATOR));
       logger.debug(metadata.get(Metadata.DATE));
       logger.debug(metadata.get(Metadata.DESCRIPTION));
      
       return properties;
    }

   @Override
   protected Parser getParser() {
      // TODO Auto-generated method stub
//      return new TiffParser();
//      return new JpegParser();
      return new ImageParser();
      
   }
   
   private Date getDateOrNull(String dateString)
    {
        if (dateString != null && dateString.length() != 0)
        {
            try {
               return dateFormat.parse(dateString);
            } catch(ParseException e) {}
        }

        return null;
    }
}
Tiene muchas lineas de prueba y loggers, para ver que es lo que se esta ejecutando.

y este es el fichero properties (el cual desconozco para que se necesita)
#
# MP3MetadataExtracter - default mapping
#
# author: Derek Hulley

# Namespaces
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
namespace.prefix.img=http://www.alfresco.es/model/pruebaimg/1.0
#namespace.prefix.img=img

# Mappings
medidaX=img:medidaX
medidaY=img:medidaY
resolucion=img:resolucion
#fecha=img:fecha
latitud=img:latitud
longitud=img:longitud
tiempoExposicion=img:tiempoExposicion
apertura=img:apertura
velocidadISO=img:velocidadISO
flash=img:flash
modoMedida=img:modoMedida
programaExposicion=img:programaExposicion
longitudFocal=img:longitudFocal
software=img:software
copyright=img:copyright

y este es el fichero que he puesto en /shared/classes/alfresco/extension –> custom-metadata-extrators-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<!–
       This sample show how to modify the mappings properties of the new V2.1 Metadata Extractors.
       In this example, in addition to the default mappings, the field 'user1' is mapped to
       'cm:description'.  The available source properties is described on the Javadocs of the
       extracter class.
–>
<beans>

    <bean id="extracter.OpenDocument" class="org.alfresco.repo.content.metadata.OpenDocumentMetadataExtracter" parent="baseMetadataExtracter" >
        <property name="inheritDefaultMapping">
            <value>true</value>
        </property>
        <property name="mappingProperties">
            <props>
                <prop key="namespace.prefix.cm">http://www.alfresco.org/model/content/1.0</prop>
                <prop key="user1">cm:description</prop>
            </props>
        </property>
    </bean>

    <bean id="extracter.Img" class="com.metadataExtraction.ImgMetadataExtracter" parent="baseMetadataExtracter" >
        <property name="inheritDefaultMapping">
            <value>true</value>
        </property>
        <property name="mappingProperties">
            <props>
                <prop key="namespace.prefix.img">http://www.alfresco.es/model/pruebaimg/1.0</prop>
                <prop key="medidaX">img:medidaX</prop>
      <prop key="medidaY">img:medidaY</prop>
      <prop key="resolucion">img:resolucion</prop>
                <prop key="latitud">img:latitud</prop>
                <prop key="longitud">img:longitud</prop>
                <prop key="tiempoExposicion">img:tiempoExposicion</prop>
                <prop key="apertura">img:apertura</prop>
                <prop key="velocidadISO">img:velocidadISO</prop>
                <prop key="flash">img:flash</prop>
                <prop key="modoMedida">img:modoMedida</prop>
                <prop key="programaExposicion">img:programaExposicion</prop>
                <prop key="longitudFocal">img:longitudFocal</prop>
                <prop key="software">img:software</prop>
                <prop key="copyright">img:copyright</prop>
            </props>
        </property>
    </bean>

</beans>

Cuando subo una imagen al repositorio, se me ejecuta el extractor, pero me da valores nulos para todas las propiedades.
También os pongo los resultados que me da el log cuando se ejecuta el extractor (según los loggers puestos en el extractor):

15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] Poniendo datos?
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] KEY_IMG_MEDIDAX: medidaX
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] Metadata.IMAGE_WIDTH.toString(): org.apache.tika.metadata.Property@3416beee
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] metadata.get(Metadata.IMAGE_WIDTH): null
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] properties: {flash=null, b=null, a=null, resolucion=null, copyright=probando copyright, tiempoExposicion=null, author=null, software=null, velocidadISO=null, title=null, latitud=null, longitudFocal=null, longitud=null, img:copyright=probando copyright 2, medidaY=null, comments=null, medidaX=null}
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] Map
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: flash
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: resolucion
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: copyright
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: tiempoExposicion
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: software
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: velocidadISO
15:17:41,519 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: apertura
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: programaExposicion
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: latitud
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: longitudFocal
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: longitud
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: modoMedida
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: medidaY
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: medidaX
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] Fin for Map
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]
15:17:41,520 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]

Como se puede observar, todas las propiedades que intento coger me dan nulas, y por tanto, cuando se crea el fichero, estas propiedades están vacías,
También he probado a poner algo de texto en una de estas propiedades, que es copyright, y cuando se crea el archivo en el Alfresco, esta propiedad también esta vacía.

Estoy haciendo algo mal?
O es que los extractores no se usan para esto?

Estoy usando alfresco 3.4d

Muchas gracias de antemano
4 Replies
ruben_arjonilla
Member II

Re: Extractor de metadatos

He modificado el ImgMetadataExtractor.java
quedando de esta manera
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package com.metadataExtraction;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.TikaPoweredMetadataExtracter;
import org.alfresco.service.namespace.QName;
import org.apache.log4j.Logger;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.metadata.TIFF;
import org.apache.tika.parser.Parser;
import org.apache.tika.parser.jpeg.JpegParser;


/**
* Extracts the following values from img files:
* <pre>
*   <b>descripcion:</b>            –      {img}:descripcion
*   <b>medidaX:</b>                –      {img}:medidaX
*   <b>medidaY:</b>                –      {img}:medidaY
*   <b>resolucion:</b>             –      {img}:resolucion
*   <b>fecha:</b>                  –      {img}:fecha
*   <b>latitud:</b>                –      {img}:latitud
*   <b>longitud:</b>                 –      {img}:longitud
*   <b>tiempoExposicion:</b>       –      {img}:tiempoExposicion
*   <b>apertura:</b>                 –      {img}:apertura
*   <b>velocidadISO:</b>           –      {img}:velocidadISO
*   <b>flash:</b>                 –      {img}:flash
*   <b>modoMedida:</b>             –      {img}:modoMedida
*   <b>programaExposicion:</b>     –      {img}:programaExposicion
*   <b>longitudFocal:</b>          –      {img}:longitudFocal
*   <b>software:</b>                 –      {img}:software
*   <b>copyright:</b>              –      {img}:copyright
* </pre>
*
*
* Uses Apache Tika
*
* @author Nick Burch
* @author Roy Wetherall
*/
public class ImgMetadataExtracter extends TikaPoweredMetadataExtracter
{
   private Logger logger = Logger.getLogger(ImgMetadataExtracter.class);
   
    private static final String KEY_IMG_MEDIDAX = "medidaX";
    private static final String KEY_IMG_MEDIDAY = "medidaY";
    private static final String KEY_IMG_RESOLUCION = "resolucion";
    private static final String KEY_IMG_FECHA = "fecha";
    private static final String KEY_IMG_LATITUD = "latitud";
    private static final String KEY_IMG_LONGITUD = "longitud";
    private static final String KEY_IMG_TIEMPO_EXPOSICION = "tiempoExposicion";
    private static final String KEY_IMG_APERTURA = "apertura";
    private static final String KEY_IMG_VELOCIDAD_ISO = "velocidadISO";
    private static final String KEY_IMG_FLASH = "flash";
    private static final String KEY_IMG_MODO_MEDIDA = "modoMedida";
    private static final String KEY_IMG_PROGRAMA_EXPOSICION = "programaExposicion";
    private static final String KEY_IMG_LONGITUD_FOCAL = "longitudFocal";
    private static final String KEY_IMG_SOFTWARE = "software";
    private static final String KEY_IMG_COPYRIGHT = "copyright";
   
    private static final String CUSTOM_PREFIX = "img:";
   
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
   
    /*
    medidaX
    medidaY
    resolucion
    fecha
    latitud
    longitud
    tiempoExposicion
    apertura
    velocidadISO
    flash
    modoMedida
    programaExposicion
    longitudFocal
    software
    copyright
    */

    public static String[] SUPPORTED_MIMETYPES = new String[] {
          MimetypeMap.MIMETYPE_IMAGE_GIF,
          MimetypeMap.MIMETYPE_IMAGE_JPEG,
          MimetypeMap.MIMETYPE_IMAGE_PNG,
          MimetypeMap.MIMETYPE_IMAGE_RGB,
          MimetypeMap.MIMETYPE_IMAGE_SVG,
          MimetypeMap.MIMETYPE_OPENDOCUMENT_GRAPHICS,
          MimetypeMap.MIMETYPE_OPENDOCUMENT_IMAGE,
    };
   
    public ImgMetadataExtracter()
    {
//        super(SUPPORTED_MIMETYPES);
        super(new HashSet<String>(Arrays.asList(SUPPORTED_MIMETYPES)));
        logger.debug("Initializing ImgMetadataExtracter logger constructor");
    }
   
    @Override
    protected Map<String, Serializable> extractSpecific(Metadata metadata, Map<String, Serializable> properties, Map<String,String> headers) {
//       putRawValue(KEY_IMG_MEDIDAX, metadata.get(XMPDM.ALBUM), properties);
//       putRawValue(KEY_SONG_TITLE, metadata.get(Metadata.TITLE), properties);
//       putRawValue(KEY_ARTIST, metadata.get(TIFF.ARTIST), properties);
      
//       putRawValue(KEY_IMG_MEDIDAX, metadata.get(Metadata.IMAGE_WIDTH), properties);
//       putRawValue(KEY_IMG_MEDIDAY, metadata.get(Metadata.IMAGE_LENGTH), properties);
//       putRawValue(KEY_IMG_RESOLUCION, metadata.get(Metadata.RESOLUTION_HORIZONTAL), properties);
//      
////       putRawValue(KEY_IMG_FECHA, getDateOrNull(metadata.get(Metadata.CREATION_DATE)), properties);
////       putRawValue(KEY_IMG_FECHA, getDateOrNull(metadata.get(Metadata.ORIGINAL_DATE)), properties);
////       putRawValue(KEY_IMG_FECHA, metadata.get(Metadata.ORIGINAL_DATE), properties);
//       putRawValue(KEY_IMG_LATITUD, metadata.get(Metadata.LATITUDE), properties);
//       putRawValue(KEY_IMG_LONGITUD, metadata.get(Metadata.ALTITUDE), properties);
//       putRawValue(KEY_IMG_TIEMPO_EXPOSICION, metadata.get(Metadata.EXPOSURE_TIME), properties);
////       putRawValue(KEY_IMG_APERTURA, metadata.get(TIFF.ALBUM), properties);
//       putRawValue(KEY_IMG_VELOCIDAD_ISO, metadata.get(Metadata.ISO_SPEED_RATINGS), properties);
//       putRawValue(KEY_IMG_FLASH, metadata.get(Metadata.FLASH_FIRED), properties);
////       putRawValue(KEY_IMG_MODO_MEDIDA, metadata.get(TIFF.ALBUM), properties);
////       putRawValue(KEY_IMG_PROGRAMA_EXPOSICION, metadata.get(Tiff.ALBUM), properties);
//       putRawValue(KEY_IMG_LONGITUD_FOCAL, metadata.get(Metadata.FOCAL_LENGTH), properties);
//       putRawValue(KEY_IMG_SOFTWARE, metadata.get(Metadata.SOFTWARE), properties);
//
////       putRawValue(KEY_IMG_COPYRIGHT, metadata.get(XMPDM.COPYRIGHT), properties);
//      putRawValue(KEY_IMG_COPYRIGHT, "probando copyright", properties);
//      putRawValue(CUSTOM_PREFIX+KEY_IMG_COPYRIGHT, "probando copyright 2", properties);
//      
//      putRawValue("a", getDateOrNull(metadata.get(Metadata.CREATION_DATE)), properties);
//      putRawValue("b", getDateOrNull(metadata.get(Metadata.ORIGINAL_DATE)), properties);
//      putRawValue("c", metadata.get(TIFF.IMAGE_WIDTH), properties);
//      
//      putRawValue(KEY_AUTHOR, metadata.get(Metadata.AUTHOR), properties);
//        putRawValue(KEY_TITLE, metadata.get(Metadata.TITLE), properties);
//        putRawValue(KEY_COMMENTS, metadata.get(Metadata.COMMENTS), properties);
       
      
       logger.debug("Poniendo datos?");
       logger.debug("KEY_IMG_MEDIDAX: "+KEY_IMG_MEDIDAX);
       logger.debug("Metadata.IMAGE_WIDTH.toString(): "+Metadata.IMAGE_WIDTH.toString());
       logger.debug("metadata.get(Metadata.IMAGE_WIDTH): "+metadata.get(Metadata.IMAGE_WIDTH));
       logger.debug("properties: "+properties.toString());
//       logger.debug("headers: "+headers.toString());
      
    // Handle user-defined properties dynamically
//       logger.debug("headers: "+headers.values().toString());
//       logger.debug("headers");
//       for (String key : headers.keySet())
//       {
//          logger.debug("key: "+key);
//          logger.debug("get key: "+headers.get(key));
//       }
      
       logger.debug("Map");
       Map<String, Set<QName>> mapping = super.getMapping();
       for (String key : mapping.keySet())
       {
          logger.debug("key: "+key);
           if (metadata.get(CUSTOM_PREFIX + key) != null)
           {
              logger.debug("dentro if key");
                putRawValue(key, metadata.get(CUSTOM_PREFIX + key), properties);
           }
       }
      
       logger.debug("Fi for Map");
      
      
       logger.debug(metadata.get(Metadata.TITLE));
       logger.debug(metadata.get(Metadata.CREATION_DATE));
       logger.debug(metadata.get(Metadata.CREATOR));
       logger.debug(metadata.get(Metadata.DATE));
       logger.debug(metadata.get(Metadata.DESCRIPTION));
      
       return properties;
    }

   @Override
   protected Parser getParser() {
      // TODO Auto-generated method stub
//      return new TiffParser();
      return new JpegParser();
//      return new ImageParser();
   }
   
   private Date getDateOrNull(String dateString)
    {
        if (dateString != null && dateString.length() != 0)
        {
            try {
               return dateFormat.parse(dateString);
            } catch(ParseException e) {}
        }

        return null;
    }
}

basicamente he modificado la función getParser() pasando de esto:
protected Parser getParser() {
      // TODO Auto-generated method stub
//      return new TiffParser();
//      return new JpegParser();
      return new ImageParser();
   }
a esto:
protected Parser getParser() {
      // TODO Auto-generated method stub
//      return new TiffParser();
      return new JpegParser();
//      return new ImageParser();
   }

y en la función extractSpecific, he comentado todos los putRawValue que había puesto anteriormente.
y ahora este es el logger que obtengo:

08:41:31,653 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] Poniendo datos?
08:41:31,653 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] KEY_IMG_MEDIDAX: medidaX
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] Metadata.IMAGE_WIDTH.toString(): org.apache.tika.metadata.Property@6706ad67
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] metadata.get(Metadata.IMAGE_WIDTH): 250
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] properties: {Number of Components=3, Image Height=167 pixels, Data Precision=8 bits, tiff:BitsPerSample=8, Component 1=Y component: Quantization table 0, Sampling factors 2 horiz/2 vert, tiff:ImageLength=167, Component 2=Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert, author=null, Component 3=Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert, title=null, tiff:ImageWidth=250, Image Width=250 pixels, comments=null}
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] Map
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: flash
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: resolucion
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: copyright
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: tiempoExposicion
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: software
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: velocidadISO
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: apertura
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: programaExposicion
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: latitud
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: longitudFocal
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: longitud
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: modoMedida
08:41:31,654 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: medidaY
08:41:31,655 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] key: medidaX
08:41:31,655 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter] Fi for Map
08:41:31,655 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]
08:41:31,655 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]
08:41:31,655 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]
08:41:31,655 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]
08:41:31,655 User:admin DEBUG [metadataExtraction.ImgMetadataExtracter]

como se puede ver a partir de la 5a linea, el properties ya tiene valores, ahora solo me falta poner esos valores dentro de mi tipo img:imagen
entiendo que esto se define en el fichero /shared/classes/alfresco/extension –> custom-metadata-extrators-context.xml, pero no consigo hacerlo funcionar correctamente, ya que cuando añado una imagen del tipo img:imagen, esta continua teniendo todas las propiedades en blanco
ruben_arjonilla
Member II

Re: Extractor de metadatos

Me he dado cuenta de una cosa.

Si en el extractor (java), pongo estas lineas:
putRawValue("prueba1", "probando 1", properties);
putRawValue("prueba2", "probando 2", properties);
putRawValue("prueba3", "probando 3", properties);
putRawValue("prueba4", "probando 4", properties);
putRawValue("prueba5", "probando 5", properties);

y en el ImgMetadataExtracter.properties pongo esto
prueba1=img:copyright
prueba2=cm:description
prueba3=cm:title
prueba4=cm:author
prueba5=cm:name

Cuando añado la imagen al repositorio, se ejecuta el extractor, y en los metadatos del archivo,
el cm:name es el mismo que el nombre del fichero que estoy subiendo
el cm:description=probando 2
el cm:title=probando 3
el cm:author=probando 4
y el img:copyright esta vacío

Es como si el extractor solo funcionara con algunos campos del cm:content, en este caso cm:description, cm:title y cm:author
Que es lo que hago mal?

Revisando por el foro, he encontrado este post:
https://forums.alfresco.com/es/viewtopic.php?f=11&t=93&p=202&hilit=extractor

en el que hablan que hay que modificar unos java del núcleo de Alfresco, pero el post es del 2007, de verdad hay que hacer estos cambios para la versión 3.4? o no tiene nada que ver?
cristinamr
Advanced

Re: Extractor de metadatos

Buenas.

Yo no tengo experiencia en este campo pero hace no mucho cybermakoki tuvo también problemas al respecto y es que el estractor de metadatos había cambiado, para la 3.4 se utiliza el Apache Tika. Ojea su hilo. Además, escribió este articulo, por si te sirve de referencia.

Un saludo.
--
VenziaIT: helping companies since 2005! Our ECM products: AQuA & Seidoc
ruben_arjonilla
Member II

Re: Extractor de metadatos

El post de cybermakoki ya me lo había leído.

En cuanto al articulo, viene a decir lo mismo que habla en el post.
Tiene que haber algún fichero que no tengo bien, o alguna cosa, o lo que digo yo de que tenga que modificar las lineas esas del código de alfresco (cosa que me extraña), pero no seria la primera vez que tengo que tocar algo del código de Alfresco…

Solo veo una diferencia entre su extractor y el mio, y es el nombre de la función donde rellenamos los datos.
Yo tengo: protected Map<String, Serializable> extractSpecific(Metadata metadata, Map<String, Serializable> properties, Map<String,String> headers) {
El tiene:  public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable

y dentro usa rawProperties en vez del properties mio.

Probare poniendo ese nombre, o coger directamente su extractor y modificarlo para que coja los metadatos que yo necesito.

Gracias por tu respuesta, ya informare cuando haya echo los cambios para ver como me ha ido