manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From piergior...@apache.org
Subject svn commit: r1452957 - in /manifoldcf/trunk: ./ connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/
Date Tue, 05 Mar 2013 19:37:45 GMT
Author: piergiorgio
Date: Tue Mar  5 19:37:44 2013
New Revision: 1452957

URL: http://svn.apache.org/r1452957
Log:
added support of created date and modified date for Alfresco (CONNECTORS-659)

Modified:
    manifoldcf/trunk/CHANGES.txt
    manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/AlfrescoRepositoryConnector.java
    manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/PropertiesUtils.java

Modified: manifoldcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/CHANGES.txt?rev=1452957&r1=1452956&r2=1452957&view=diff
==============================================================================
--- manifoldcf/trunk/CHANGES.txt (original)
+++ manifoldcf/trunk/CHANGES.txt Tue Mar  5 19:37:44 2013
@@ -2,6 +2,9 @@ ManifoldCF Change Log
 $Id$
 
 ======================= 1.2-dev =====================
+CONNECTORS-659: Alfresco connector created date and modified date support
+(Piergiorgio Lucidi)
+
 CONNECTORS-656: Add mimetype and/or filename support to CMIS connector
 (Piergiorgio Lucidi)
 

Modified: manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/AlfrescoRepositoryConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/AlfrescoRepositoryConnector.java?rev=1452957&r1=1452956&r2=1452957&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/AlfrescoRepositoryConnector.java
(original)
+++ manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/AlfrescoRepositoryConnector.java
Tue Mar  5 19:37:44 2013
@@ -22,6 +22,7 @@ package org.apache.manifoldcf.crawler.co
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InterruptedIOException;
+import java.text.ParseException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -812,17 +813,10 @@ public class AlfrescoRepositoryConnector
         try {
           //properties ingestion
           RepositoryDocument rd = new RepositoryDocument();      
-          PropertiesUtils.ingestProperties(rd, properties);
+          List<NamedValue> contentProperties = PropertiesUtils.getContentProperties(properties);
+          PropertiesUtils.ingestProperties(rd, properties, contentProperties);
 
           // binaries ingestion - in Alfresco we could have more than one binary for each
node (custom content models)
-          List<NamedValue> contentProperties = PropertiesUtils.getContentProperties(properties);
-          
-          String fileName = PropertiesUtils.getPropertyValues(properties, Constants.PROP_NAME)[0];
-          String mimeType = PropertiesUtils.getMimeType(contentProperties);
-          
-          rd.setFileName(fileName);
-          rd.setMimeType(mimeType);
-          
           for (NamedValue contentProperty : contentProperties) {
             //we are ingesting all the binaries defined as d:content property in the Alfresco
content model
             Content binary = ContentReader.read(username, password, session, predicate, contentProperty.getName());
@@ -849,6 +843,12 @@ public class AlfrescoRepositoryConnector
             activities.ingestDocument(id, version, documentURI, rd);
           }
           
+        } catch (ParseException e) {
+          errorCode = "IO ERROR";
+          errorDesc = e.getMessage();
+          Logging.connectors.warn(
+              "Alfresco: Error during the reading process of dates: "
+                  + e.getMessage(), e);
         } finally {
           try {
             if(is!=null){

Modified: manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/PropertiesUtils.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/PropertiesUtils.java?rev=1452957&r1=1452956&r2=1452957&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/PropertiesUtils.java
(original)
+++ manifoldcf/trunk/connectors/alfresco/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/alfresco/PropertiesUtils.java
Tue Mar  5 19:37:44 2013
@@ -18,7 +18,10 @@
  */
 package org.apache.manifoldcf.crawler.connectors.alfresco;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 
@@ -39,6 +42,15 @@ public class PropertiesUtils {
   private static final String PROP_CONTENT_SEP = "|";
   private static final String PROP_MIMETYPE_SEP = "=";
   
+  private final static ThreadLocal<SimpleDateFormat> ISO8601_DATE_FORMAT =
+      new ThreadLocal<SimpleDateFormat>() {
+             protected SimpleDateFormat initialValue() {
+                  return new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.mmm+hh:mm");
+              }
+       };
+
+  private static final String PROP_MODIFIED = Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL,
"modified");
+  
   public static String[] getPropertyValues(NamedValue[]  properties, String qname){
     String[] propertyValues = null;
     for(NamedValue property : properties){
@@ -53,7 +65,7 @@ public class PropertiesUtils {
     return propertyValues;
   }
   
-  public static void ingestProperties(RepositoryDocument rd, NamedValue[] properties) throws
ManifoldCFException{
+  public static void ingestProperties(RepositoryDocument rd, NamedValue[] properties, List<NamedValue>
contentProperties) throws ManifoldCFException, ParseException{
     for(NamedValue property : properties){
       if(property.getIsMultiValue()){
         String[] values = property.getValues();
@@ -66,6 +78,16 @@ public class PropertiesUtils {
         rd.addField(property.getName(), property.getValue());
       }
     }
+    
+    String fileName = PropertiesUtils.getPropertyValues(properties, Constants.PROP_NAME)[0];
+    String mimeType = PropertiesUtils.getMimeType(contentProperties);
+    Date createdDate = PropertiesUtils.getDatePropertyValue(properties, Constants.PROP_CREATED);
+    Date modifiedDate = PropertiesUtils.getDatePropertyValue(properties, PROP_MODIFIED);
+     
+    rd.setFileName(fileName);
+    rd.setMimeType(mimeType);
+    rd.setCreatedDate(createdDate);
+    rd.setModifiedDate(modifiedDate);
   }
   
   /**
@@ -160,4 +182,16 @@ public class PropertiesUtils {
     return StringUtils.EMPTY;
   }
   
+  /**
+   * 
+   * @param properties
+   * @return version label of the latest version of the node
+   * @throws ParseException 
+   */
+  public static Date getDatePropertyValue(NamedValue[] properties, String qname) throws ParseException{
+    String dateString = PropertiesUtils.getPropertyValues(properties, qname)[0];
+    //String finalDateString = dateString.replaceAll(ISO8601_REPLACE, ISO8601_REPLACE_TO);
+    return ISO8601_DATE_FORMAT.get().parse(dateString);
+  }
+  
 }



Mime
View raw message